C# MultiColumn Listbox

13,258

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
}
Share:
13,258
Cocoa Dev
Author by

Cocoa Dev

Updated on June 04, 2022

Comments

  • Cocoa Dev
    Cocoa Dev almost 2 years

    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

  • Lord of Scripts
    Lord of Scripts over 7 years
    The OP is using a ListBox control, not a ListView.