C# MultiColumn Listbox

北城余情 提交于 2019-12-11 02:27:07

问题


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:


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
}


来源:https://stackoverflow.com/questions/8477212/c-sharp-multicolumn-listbox

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