Anyway to expose ListView.Columns property?


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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?
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Perfect! Thanks!
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Not a problem... that's one of the first "gotchas" that you learn when working with type editors... Whistling
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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?
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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?
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
When I attempt to open the type editor I get an error. I've attached a screen shot of the message box.
Attachments
ToolStripItems_TypeEditorError.bmp (146 views, 180.00 KB)
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
I'm not sure... I'll have to test this.  That's not our type editor, though... it's .NET's type editor.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search