【问题标题】:Updating the value of a subItem in a ListViewItem inside a listview c# (Winforms)在listview c#(Winforms)中更新ListViewItem中子项的值
【发布时间】:2012-04-16 22:13:35
【问题描述】:

我想更新包含在 ListView 中的 ListviewItem 中的数据。 The idea is when a row of the listview is selected, I click on a button and the data is updated .

我有这个代码:

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]  ....... ;
}

我知道如何进一步访问 access 以将“my brother”的值修改为“myister”。

提前致谢。

【问题讨论】:

    标签: c# winforms listview listviewitem


    【解决方案1】:

    检查是否选择了某些内容,然后访问 SelectedItems 中的第一个 ListViewItem

    if(listView1.SelectedItems != null)
    {
       ListViewItem item = listView1.SelectedItems[0];
       item.SubItems[0].Text = "Sister";
    }
    

    这是 ListViewSubItem 类的reference on MSDN

    【讨论】:

    • 你是我的英雄。感谢您的快速回答。
    猜你喜欢
    • 2012-11-16
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多