Saturday, March 29, 2014

ListView in C#

Why only one columns displayed, and not seeing columns and items in GUI?
Set View Property of Listview to Details

Adding Columns to ListView
GListView.Columns.Add("a");
GListView.Columns.Add("b");
GListView.Columns.Add("c");

Adding Items to ListView
var item1 = new ListViewItem(new[] { "id123", "Tom", "24" });
GListView.Items.Add(item1);

-or-

 var item1 = new ListViewItem();
item1.Text = "id123";
item1.SubItems.Add("Tom");
item1.SubItems.Add("24");
GListView.Items.Add(item1);

(items1 is the first columns, and it contains subitems (other columns)


Modifying
First Column (both below are ok)
GListView.Items[0].Text = "haha";

 GListView.Items[0].SubItems[0].Text= "haha1";

Second Column
 GListView.Items[0].SubItems[1].Text= "haha1";

No comments:

Post a Comment