Link to home
Start Free TrialLog in
Avatar of Declan Basile
Declan BasileFlag for United States of America

asked on

Multiple Column Listbox in VB.net

I'm a veteran Microsoft Access developer now working in vb.net.  To create a multiple column listbox with column headers in Access I simply had to set the ColumnCount property to the number of columns and the ColumnHeads property to "Yes".  Now using the listbox control in VB.net it looks like I only have an opportunity to specify one column of data to be displayed by setting the "DisplayMember" property.  Ultimately I need to present the user with a popup form the has 7 columns of data (there should never be more than 10 rows) and return a value (not displayed but associated to that row) after the user double clicks one of the rows).  I realize I could format the displayMember's data into tabbed columns myself, but have to believe there's a better way.  I also know about the multicolumn property but this is not what I need, for that just displays one column (i.e. field) of the datasource in multiple columns.  How else can I accomplish this in VB.net?  Is there a third party listbox control that I could use?  Would I be better off using the datagridview control to display multiple columns of data even though the user doesn't have to (in this case) edit the data but just has to double click one of the rows?
SOLUTION
Avatar of Najam Uddin
Najam Uddin
Flag of United States of America 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
SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation 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
ASKER CERTIFIED SOLUTION
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
If you replace your overrided ToString method with (VB doesn't understand char literals)
Return String.Format("{0}\t{1}\t{2}\t{3}", ID, Name, Birthdate.ToShortDateString(), IsWorking).Replace("\t", vbTab)

Open in new window

you'll see columns in a listbox
You can specify column width
ListBox1.UseCustomTabOffsets = True
ListBox1.CustomTabOffsets.AddRange(New Integer() {50, 100})

Open in new window

Knowing column width you can add "headers" as labels above listbox
Avatar of Declan Basile

ASKER

The DataGridView worked well for me.  Thank you.