C# - 更新列表视图中的子项

发布于 2024-08-08 10:43:20 字数 293 浏览 3 评论 0 原文

我正在开发一个应用程序,用户输入信息然后将其添加到列表视图中。效果很好。唯一的问题是,应用程序连接到一个网站,该网站会更新每个帐户的列表视图中的“积分”字段。我不确定如何更新列表视图中的单个子项。

以下是屏幕截图示例:

如何选择特定行中的特定子项进行更新?

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:

alt text

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灰色世界里的红玫瑰 2024-08-15 10:43:20

好的,我将假设使用 Windows 窗体。

WinForms 的 ListViewItem 类有一个 名称属性,您可以使用它来查找列表中的特定项目。因此,当您填充列表时,请为每个名称分配一个唯一值:

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

这样您就可以稍后使用其 Items.Find 方法。

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

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);
行至春深 2024-08-15 10:43:20

为了扩展 Matt 的答案,看起来每一行都有一个唯一的电子邮件地址,因此您可以将其分配为每个 ListViewItem 的 Name 属性。使用 Find 方法找到要更新的行后,您可以像这样更新该行的 Points:

fooItem.SubItems[2] = "450";

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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文