Stieve wrote:
my final goal is to create a dynamic listview.
i would like to create a user controle where i send a collection of
unique typed objects to and it populates the listview dynamical.
i want it to use the names of the attributes of the objects as columns
and then populate it with the values in attribute.
An alternative for you:
To each class that you want to display in this way, add a method that
"renders" your class into a given ListView.
For consistency, you probably want to do this with an Interface.
Interface ICanBeListViewed
Function GetColumns() As String()
Sub Render( lvDisplay as ListView )
End Interface
Class X
Implements ICanBeListViewed
Function GetColumns() As String()
' Return an array of column names
Return New String() { "a", "b" }
End Function
Sub Render( lvDisplay as ListView ) _
Implements ICanBeListViewed.Render
' In here, add an Item and Subitems into the given ListView
With lvDisplay.Items.Add( "a value" )
.SubItems.Add( "b value" ) ' (I think)
End With
End Sub
End Class
Now, to load the ListView, you create Columns based on the GetColumns()
value of one of the items in your collection, then Render() each object
into the ListView.
HTH,
Phill W.