C# - Update a subitem within a listview

泄露秘密 提交于 2019-12-22 07:05:23

问题


I am working on an application where users enter information that is then added to a listview. That works great. The only problem is, the application connects to a web site that updates the "Points" field in that listview for each account. I am not sure how I can update a single subitem within a listview.

Here is an example screenshot:

How can I select a specific subitem in a specific row to update?


回答1:


Ok, I'm going to assume Windows Forms.

WinForms' ListViewItem class has a Name property, which you can use to look up a specific item in a list. So as you populate the list, assign a unique value to the Name of each:

var item = new ListViewItem("Text");
item.Name = "foo"; // some unique id string
listView1.Items.Add(item);

That way you can locate the item in the ListView later, using its Items.Find method.

var fooItem = listView1.Items.Find("foo", false);



回答2:


To expand on Matt's answer, it looks like each row has a unique email address, so you could assign that as the Name property for each ListViewItem. Once you've located the row to update using the Find method, you can update that row's Points like this:

fooItem.SubItems[2] = "450";


来源:https://stackoverflow.com/questions/1622564/c-sharp-update-a-subitem-within-a-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!