如何以编程方式编辑选定子项? [英] How to edit a selected SubItem programmatically?

查看:133
本文介绍了如何以编程方式编辑选定子项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我可以在一个ListView编辑子项目?我已经使用这个尝试:

Does anyone know how can I edit a subitem on a listView? I've tried using this:

ListView1.SelectedItems[0].SubItems[1].Text = "Hello?";

但是,这并不工作。我得到的错误的'1'= InvalidArgument值是无效的索引。我有在列表视图两列,所以我的[1]将是分项指数。

But that doesn't work. I get the error "InvalidArgument=Value of '1' is not valid for 'index'". I've got two columns on the listview, so I figured the index of [1] would be the subitem.

推荐答案

让你实际上有子项到列表中增加了一个项目?只是因为你有两列的ListViewItem不会自动获得2子项。

Have you actually added an item with a subitem to the list? Just because you have two columns the ListViewItem doesn't automatically get 2 subitems.

例如,如果你做了以下内容:

For example if you have done the following:

ListViewItem item = listView1.Items.Add("test");  
item.SubItems.Add("sub1");

那么它应该工作,但是如果你只有:

Then it should work, but if you only have:

ListViewItem item = listView1.Items.Add("test");

那么就不会。

这篇关于如何以编程方式编辑选定子项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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