Multiple columns in List box control

2019-06-20 19:42发布

how can i display two columns in a list box?

9条回答
放我归山
2楼-- · 2019-06-20 20:07

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.

查看更多
老娘就宠你
3楼-- · 2019-06-20 20:08

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

查看更多
一纸荒年 Trace。
4楼-- · 2019-06-20 20:08

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" >
查看更多
beautiful°
5楼-- · 2019-06-20 20:12

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:

enter image description here

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).

查看更多
迷人小祖宗
6楼-- · 2019-06-20 20:14

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>
查看更多
贪生不怕死
7楼-- · 2019-06-20 20:21

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.

查看更多
登录 后发表回答