I am trying to programmatically update a listview and its items in my winForm app. I have it working with literal commands:
ListViewItem item8 = new ListViewItem();
item8.Text = "Windows Server Resource Kit";
this.listView1.Items.Add(item8);
What I really want to do is to do this programmatically. Something like:
public void _updateList(string strApp, string strStatus)
{
ListViewItem li = new ListViewItem();
if (strApp != null)
{
li.Text = strApp;
listView1.Items.Add(li)
}
}
but that is not getting me very far. Anyone have an idea for this one. I guess another way to put it is I want to be able to edit each listviewitem's subitems. Not sure if I need to do an array to get this done or not. Any help is appreciated. Chuck
charlesPosted Jun 24, 2008, 2:00 PM
I have the listview adding the items to the 1st column of the details view. I can also get the lv to add in a subitem. But for some reason the subitem will not update. Here is what I have:
ListViewItem
item15 = new ListViewItem();item15.Text = "Some Text";
lv.Items.Add(item15);
lv.Items[lv.Items.Count - 1].EnsureVisible();
item15.SubItems.Add(
"Some Text");Now, if want to change the value of only the subitem I should be able to use: item15.SubItems.Add("Some Other Text");
but for whatever reason it is not updating the subitems text. I have also tried using lv.Items[14].SubItems.Add("Error During Install"); and also lv.Items["some text"].SubItems[0].Text = "Some Other Text";
All to no Avail. Any help on doing this would be great.
Jan MontanoPosted Jun 18, 2008, 5:24 AM
{
//initialize list view
listView1.View = View.Details;
ColumnHeader columnHeader1 = new ColumnHeader();
ColumnHeader columnHeader2 = new ColumnHeader();
ColumnHeader columnHeader3 = new ColumnHeader();
ColumnHeader columnHeader4 = new ColumnHeader();
columnHeader1.Text = "Name";
columnHeader2.Text = "Color One";
columnHeader3.Text = "Color Two";
columnHeader4.Text = "Color Three";
listView1.Columns.Add(columnHeader1);
listView1.Columns.Add(columnHeader2);
listView1.Columns.Add(columnHeader3);
listView1.Columns.Add(columnHeader4);
ListViewItem lvi = new ListViewItem("Naruto");
lvi.SubItems.Add("Blue");
lvi.SubItems.Add("Red");
lvi.SubItems.Add("Green");
ListViewItem lvi2 = new ListViewItem("Sasuke");
lvi2.SubItems.Add("Gold");
lvi2.SubItems.Add("Silver");
lvi2.SubItems.Add("Orage");
listView1.Items.Add(lvi);
listView1.Items.Add(lvi2);
}
private void button4_Click(object sender, EventArgs e)
{
//edit subitem
listView1.Items[1].SubItems[1].Text = "Gold Modified";
}