如何以编程方式编辑选定子项?
问题描述:
有谁知道我可以在一个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");
那么就不会。