问题
I would like to update the data contained in a ListviewItem contained itself in a ListView. The idea is when a row of the listview is selected, I click on a button and the data is updated .
I have this code :
ListView listView1 = new System.Windows.Forms.ListView();
ListViewItem lv1 = new ListViewItem("me");
lv1.SubItems.Add("my brother");
listView1.Items.Add(lv1);
Button myB = new System.Windows.Forms.Button();
private void myB_Click(object sender, EventArgs e)
{
listView1.SelectedItems[0] ....... ;
}
I know how to go any further to acces to modify the value of "my brother" to "my sister".
Thanks in advance.
回答1:
Check if something is selected then access the first ListViewItem in the SelectedItems
if(listView1.SelectedItems != null)
{
ListViewItem item = listView1.SelectedItems[0];
item.SubItems[0].Text = "Sister";
}
this is the reference on MSDN for ListViewSubItem class
来源:https://stackoverflow.com/questions/10182463/updating-the-value-of-a-subitem-in-a-listviewitem-inside-a-listview-c-sharp-win