简体   繁体   中英

displaying data inside listview

I'm using listbox to display list of data, I tried with this

foreach (MyData a in data)
{     
    var row = new ListViewItem();
    row.Text = a.Name;
    row.SubItems.Add(a.Code);
    row.SubItems.Add(a.Name2);    
    listView1.Items.Add(row);
}

This way I'm getting data displayed inside columns and I need to display inside row, also subitems Code and Name2 are not displayed.

What I'm doing wrong here

In order to see subitems you need to use Details mode of ListView . Also make sure you have added three columns to listview (you can do it in designer):

listView.Columns.Add("Name");
listView.Columns.Add("Code");
listView.Columns.Add("Name2");
listView.View = View.Details;
// ... your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM