Link to home
Start Free TrialLog in
Avatar of DColin
DColinFlag for Thailand

asked on

ListView column headers

Hi Experts,

If I have an arraylist populated with a customer class:

customer.firstName
customer.lastName
customer.age

It is possible to bind a listview control to this arraylist so that the column header names are automatically taken from the class members so that the column headers would be:
firstname, lastName, age.
Avatar of miketonny
miketonny

if your first three items in your arraylist are the headers then you can do something like

 
 Dim customerList() as your class
            ListView1.View = View.Details
            ListView1.Columns.Add(customerList(0), 50, HorizontalAlignment.Center)
            ListView1.Columns.Add(customerList(1), 50, HorizontalAlignment.Center)
            ListView1.Columns.Add(customerList(2), 20, HorizontalAlignment.Center)

Open in new window

Avatar of DColin

ASKER

miketonny:

The header names are not part of the array.

Is it possible to access the class members name. So for example:

customer.firstName.membername would return "firstName"?
Avatar of Nasir Razzaq
What are you trying to achieve? Make the display display any collection? Why not use a DataTable and a DataGridView?
Avatar of DColin

ASKER

CodeCruiser:

Yes I am trying to create a display table that will display any class or data type and automatically set to headers to the name of the data variable.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial