ListView column headers

Posted on 2011-05-10
Medium Priority
Last Modified: 2012-06-27
Hi Experts,

If I have an arraylist populated with a customer class:


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.
Question by:DColin
  • 2
  • 2

Expert Comment

ID: 35733043
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


Author Comment

ID: 35735660

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"?
LVL 83

Expert Comment

ID: 35736266
What are you trying to achieve? Make the display display any collection? Why not use a DataTable and a DataGridView?

Author Comment

ID: 35736595

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.
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 35736887
You can use Reflection to get all the properties of the class but then you would have to add columns to the listview before populating it as Listview does not create columns automatically (but the DataGridView does).


Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question