Thanks. That would probably solve it for a ListView that is designed using
the forms designer (which is good, but not the only requirement).
But will it also work if I want to add columns at runtime? I mean, when
MyListViewColumn is inherited from ColumnHeader, can I actually do:
Dim MyColumn as MyListViewColumn
MyListView.Columns.Add(MyColumn)
When the ListView is expecting a System.Windows.Forms.ColumnHeader - not a
MyNameSpace.MyListViewClass.MyListViewColumn ????
And of course, I would like to be able to edit the columns collection at
designtime using the Collection editor with MyListViewColumns instead of
ColumnHeaders???
Cheers,
Johnny J.
Yes you can do MyListView.Columns.Add because it's expecting a
ColumnHeader and you ARE giving it a column header. MyListViewColumn
inherits from ColumnHeader. It is a _type_ of ColumnHeader, just like
a LinkedList asks for an "object" and you can provide anything that
derives from it, you can treat this exactly like a columnheader. It
has the same functions, properties etc. This feature is called
Inheritence and it's a benefit of Object-Oriented programming. Perhaps
you may be a little more confident if you read up more.
How here's something to be aware of. You give a MyColumnHeader which
happily goes into a MyListView.Columns, but that collection will
always be a type of "HeaderColumnCollection". The list view itself is
unaware of the extra data. (It doesn't get lost or forgotten) but when
you come to access it like this:
MyListView.Columns(0) 'first column header.
This will be a type *considered* a type of ColumnHeader, not
MyColumnHeader. You will need to explicitly "cast" the object back
into the correct type you know that it is:
dim myColumn As MyColumnHeader =
directcast(mylistview.Columns(0),MyColumnHeader)
First, on the right hand side of the equals, I explicitly say the
record at Column(0) is a MyColumnHeader. Then I assign it to myColumn.
if you have MyColumnHeaders and regular ColumnHeaders all mixed up you
will need to test it first. This sets the "ColumnID" property we made
earlier:
if (typeof mylistview.columns(0) is MyColumnHeader) then
'this is my special column header, set the column id
directcast(mylistview.columns(0).ColumnID = 78
else
'there is no column id on this column header because it's just
a regular plain old one
end if
-
Anyway hope this helps some more. Reading a little about Object
Inheritance may help you if you don't already know it.