views:

390

answers:

5

how can i display two columns in a list box?

A: 

Looks like you should write your own control, or you can use the listview control.

Haranadh Gupta
A: 

See Multiple Column Drop-Down Box for ASP.NET

KMan
there is no such control as mulicolumn list box
xrx215
@xrx215: If you go through the article you would learn that `MultiColumnListBox` is a *subclassed* control.>This is an Owner Drawn ListBox *inherited from `System.Windows.Forms.ListBox`*. Its primary function is to format each Item into multiple columns.Which is what others have suggested.
KMan
Question is tagged asp.net, link isn't relevant.
meagar
@Meager: Thanks for pointing out; checkout the link now.
KMan
+1  A: 

You could line it up as if the data was in 2 columns

new ListItem("blah1".PadRight(10, ' ') + "blah2");

as shown here: http://articles.dotheweb.net/post/Formatting-columns-in-a-ListBox-of-ComboBox.aspx

Also, you could roll your own with a DataList.

Homer
A: 

As Nick Craver has already commented, the ListView probably isn't the right control for multi-column information.

Instead of hacking your list to appear as if it has two columns, it might be a better idea to use a DataGridView. It'll be easier to setup, format, and your data will be held in a much more flexible way.

DataGridViews also support assigning Lists of objects as datasources, if that makes things easier.

TeeBasins
+2  A: 

A list box wasn't designed to display multi-column data. Even the Windows Forms version doesn't directly support that kind of data display.

Your requirements aren't clear, but the simplest way to go would be to use a GridView control. It gives you a lot of functionality out of the box, and you can expand it to more columns very easily. If you need more control over the look or functionality, you can use a DataList instead.

To get the scrolling ability, you can either use a scrolling <div> or simply use the pagination mechanism of the GridView if that's appropriate.

Jon Seigel
i m using div to scroll down and repater to dispaay the data..thanks..
xrx215