Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Vs ListBox

Status
Not open for further replies.

tEkHEd

IS-IT--Management
Jan 29, 2003
261
GB
I am struggling a little with the move from VB to .NET and was wondering if anyone can give me any pointers as to which is best to return data from a query or routine?

AFAIK the listbox in .NET can only accept 1 column? Can anyone tell me why?

Also I would like to know how to populate a datagrid, as I have a WMI query which enumerates various OS properties that I would like to display in a multi-column list.

A further question..

Is there still a OnDoubleClick event? I cannot seem to get this to work..

Cheers in adv for any advice/tips/sites etc...
 
Well, I cannot give you exact answer on ur question but I had same problems last few weeks.

I've been to many of vb.net sites and many vb programmers are complaining about list box on vb.net.(multi-column)

Saddly, I hardly see the way to solove this problem on list box. They are just suggesting to use datagrid instead.

I can say using datagrid intead listbox is bit more complicated..

Cheers.
 
Another option is to use the ListView control. Its much more powerful than the Listbox, and worth spending the time to get to know it. We subclassed this, and added custom properties so we could control which datatable fields to include, column widths, alignment etc...

There is some good sample code in the help files to get you started

What we ended up with was a listview class we use as such

Code:
With lvlens
   .oSelectedBackColor = Color.Turquoise
   .sFieldList = "Cutqty,Cutlength" 'Fields required
   .sColumnHeaders = "Qty,Cut Length" 'Column Headers
   .sColumnWidths = "40,70" 'Column Widths
   .sColumnSort = "2,2" 'Column Sort Order 0-None,1-Asc,2-Desc
   .sColumnAlignMent = "R,R" 'Column Alignment Left/Right
   .zBuild(dtMlens) 'dtMlens is a Datatable
End With

It is also however possible to subclass the Listbox so you can have as many columns as you require. We've done exactly the same with the ComboBox. The trick is to override the Base controls Paint Event.



Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top