Multiple columns in List box control

心已入冬 提交于 2019-12-23 09:34:38

问题


how can i display two columns in a list box?


回答1:


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.




回答2:


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.




回答3:


If you want to use columns in a ListBox, you have to do it based on alignment.

For example:

String columns = "{0, -55}{1, -35}{2, -35}";
ListBox1.Items.Add(String.Format(columns, "Filename", "Selected DateModified", "Vault DateModified"));
ListBox1.Items.Add(String.Format(columns, fileName, datetime1, datetime2));  

Output of my own implementation of this code below:

Keep in mind the font you use has to be a monospaced font, otherwise the alignment will mess up due to variable spacing between characters (and this exaggerates the longer the string is).




回答4:


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




回答5:


use list view it is perfect alternative for multi column list box




回答6:


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.




回答7:


If I understood correctly, you want a data column to display horizontal. This can be acheived by using a DataList and have RepeatDirection set to "Hozizontal" with the specified repeat columns. Eg :

<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="5" CellSpacing="10" >



回答8:


Multiple items side by side are possible if you reference the toolkit and add the wrapPanelOrientation ;) it will list look like

1stItem      2ndItem

3rdItem      4thItem .. ect..

ListBox.ItemsPanel>

ItemsPanelTemplate>
    toolkit:WrapPanelOrientation="Horizontal"FlowDirection="LeftToRight"ItemWidth="220"ItemHeight="60"/>

/ItemsPanelTemplate>

/ListBox.ItemsPanel>

/ListBox>



回答9:


See Multiple Column Drop-Down Box for ASP.NET



来源:https://stackoverflow.com/questions/2646446/multiple-columns-in-list-box-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!