Reputation: 3515
I'm displaying data inside listview as I'm suggested in previous quesiton but I'm having mistake. Data should display like this
CODE | NAME | PRICE
--------------------
122a myname 122.99
but I'm having this
CODE | NAME | PRICE
--------------------
122a myname
Code is following
listView1.Columns.Add("Code");
listView1.Columns.Add("Name");
listView1.Columns.Add("Price");
foreach (MyData in dataList)
{
var row = new ListViewItem();
row.SubItems.Add(a.Code);
row.SubItems.Add(a.Name);
row.SubItems.Add(a.Price.ToString("F"));
listView1.Items.Add(row);
}
listView1.View = View.Details;
Upvotes: 0
Views: 94
Reputation: 216353
The text for the first column should be added as the ItemText at ListViewItem constructor
foreach (MyData in dataList)
{
var row = new ListViewItem(a.Code);
row.SubItems.Add(a.Name);
row.SubItems.Add(a.Price.ToString("F"));
listView1.Items.Add(row);
}
You could check the example on the ListViewItem.SubItems topic on MSDN
Upvotes: 1