更新ListView C#中的ListViewItem中的subItem的值(Winforms) [英] Updating the value of a subItem in a ListViewItem inside a listview c# (Winforms)

查看:1048
本文介绍了更新ListView C#中的ListViewItem中的subItem的值(Winforms)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新ListViewItem中包含的ListviewItem中包含的数据. 我们的想法是当选择了列表视图的一排,我点击一个按钮,数据被更新.

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 .

我有此代码:

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".

提前谢谢.

推荐答案

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

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";
}

这是MSDN上的引用 ListViewSubItem类

this is the reference on MSDN for ListViewSubItem class

这篇关于更新ListView C#中的ListViewItem中的subItem的值(Winforms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆