C# MultiColumn Listbox

2019-07-21 11:43发布

I have two the following code

    List<string> _items = new List<string>();
    List<string> _items2 = new List<string>();

I want to add both of them into a single multi-column Listbox

Column1 could be _items whereas Column2 can be _items2

I don't know how to add items2 to a 2nd column

I've added _items to the Listbox by

Listbox1.DataSource = _items

Thank you

1条回答
放我归山
2楼-- · 2019-07-21 12:15

The above answer did not work for me, using .NetCF, this slight variation did:

myListView.Columns.Add("Nr"); //column 1 heading
myListView.Columns.Add("Desc"); //column 2 heading
myListView.View = View.Details; //make column headings visible
foreach (var item in someDataList) //item has strings for each column of one row
{
    // create new ListViewItem
    ListViewItem lvi = new ListViewItem(item.Text1);
    lvi.SubItems.Add(item.Text2);
    // add the listviewitem to a new row of the ListView control
    myListView.Items.Add(lvi); //show Text1 in column1, Text2 in col2
}
查看更多
登录 后发表回答