Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How can automatically-generated ListView ColumnHeader objects be preserved in design mode?
 

How can automatically-generated ListView ColumnHeader objects be preserved in design mode?

Ok, I'm back for more. I have been successful for the most part in my objective of creating a databound ListView control that inherits from the regular ListView control (in .Net 2.0).

The control behaves adequately for the most part and I decided to enhance the design-time support. Have you seen how the DataGridView control can generate the columns from the data schema? Well, I want that for my ListView.

The schema part is no problem, and I thought I had set up the DesignerActionMethodItem in no time. And it actually adds the columns. The problem: The columns are not being preserved in the .Designer.cs file of the form, so if the form is closed and reopened, the columns are just not there anymore.

The databound ListView's Columns property has already applied the DesignerSerializationVisibilityAttribute attribute with a visibility of "Content", and the columns are serialized properly whenever changed by the Columns editor. How can I therefore have my automatically-generated columns serialized to the designer file?

Also note that the Undo of the designer does not list the column additions as an undoable action. I would also like to gain this ability.
MCP
webJose  Friday, September 25, 2009 7:35 PM
After a lot of trial and error, I got it. I did not know that ListView column headers inherited from Component. It seems that this is a requirement because they have to be added to the logical container to be persisted:

this.Component.Site.Container.Add(header);

After they are added to the container, they appear serialized in the form's designer file.
MCP
  • Marked As Answer bywebJose Friday, September 25, 2009 10:23 PM
  •  
webJose  Friday, September 25, 2009 10:23 PM
After a lot of trial and error, I got it. I did not know that ListView column headers inherited from Component. It seems that this is a requirement because they have to be added to the logical container to be persisted:

this.Component.Site.Container.Add(header);

After they are added to the container, they appear serialized in the form's designer file.
MCP
  • Marked As Answer bywebJose Friday, September 25, 2009 10:23 PM
  •  
webJose  Friday, September 25, 2009 10:23 PM

You can use google to search for other answers

Custom Search

More Threads

• Form designer & setting visibility
• Designer Form Error - Service Type
• Masked TextBox formatting question
• Problems serializing a collection out of Windows form Collection Editor
• Is there a fix for VS2005 crash when viewing infopath/FormControl property?
• AutoToolboxPopulate not working
• Form in splicontainer wont resize when resizing splitcontainer !
• transparant background picturebox
• Container control refresh issue
• How to create new property (cols,Rows) to DataGridView