StrataFrame Forum

Anyway to expose ListView.Columns property?

http://forum.strataframe.net/Topic4788.aspx

By Greg McGuffey - 11/27/2006

I have a SF Usercontrol that has a SF ListView on it. I would like to expose the Columns property as a public property of the Usercontrol, as this is needed to configure it (and I'd like to keep it declarative).



The problem is that the Columns property is Readonly (.Net limitation). I've tried defining the property as a ColumnHeaderCollection. This works fine for the Get section, but in the Set section I have to use code like:



For each col As ColumnHeader in value

Me.lvwAny.Columns.Add(col)

Next col



The property then shows up in the property windows and allows me to set columns, which show up at runtime. However as soon as I build it, the columns aren't associated with the ListView either at runtime or when I go back into design mode, though they are defined within the designer (i.e. individual ColumnHeader objects are defined, but not associated with the ListView at all).



Any ideas on how I might do this?
By StrataFrame Team - 11/28/2006

You'll probably have your best luck by setting the property to ReadOnly and add this attribute to the property:

<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)> _

That tells the designer to "serialize" the columns into the InitializeComponent() method.

By Greg McGuffey - 11/28/2006

Perfect! Thanks!
By StrataFrame Team - 11/28/2006

Not a problem... that's one of the first "gotchas" that you learn when working with type editors... Whistling
By Greg McGuffey - 11/28/2006

OK, I must have moved onto the second gotcha Crazy...



I tried the same sort of thing to expose the Items collection of a SF ThemedToolStrip and I get a parameter is null error for the value parameters. I set up the property as readonly, so I don't know were this value parameter is coming from (the type editor I'm guessing).



You have any idea of what going on here?
By StrataFrame Team - 11/28/2006

That's strange, the Items property is ReadOnly... what does the error message you're receiving say exactly? and when do you get the error message? when you open the type editor, or when you try to exit the type editor and save your changes?
By Greg McGuffey - 11/28/2006

When I attempt to open the type editor I get an error. I've attached a screen shot of the message box.
By StrataFrame Team - 11/28/2006

I'm not sure... I'll have to test this.  That's not our type editor, though... it's .NET's type editor.
By Greg McGuffey - 11/28/2006

Thanks. Yeah, I know it is the .NET type editor. Also, unless there is some way to associate code to the click event of any buttons added via the designer, I'm not sure it's worth it (otherwise, I've got a button that does nothing). I've exposed the ToolStrip itself and can add buttons and handle events of the button this way.
By StrataFrame Team - 11/28/2006

Yeah, exposing the toolstrip is a good way to do it... most likely, the type editor is trying to access the "parent" of the property being edited and directcasting it to ToolStrip, which you user control is not.  So, exposing the whole thing would probably be your best bet.

As for attaching handlers to the click events of buttons added in the first designer, you'll have to do that programmatically like this:

AddHandler Me.ToolStripProperty.Items(0).Click, AddressOf MyButton_Click

By Greg McGuffey - 11/28/2006

ah....Satisfied