简体   繁体   English

如何启用/禁用列表视图子项编辑

[英]How to enable/disable listview subitem editing

I've created a checked listview programmatically, with one of the columns being an editable textbox. 我已经以编程方式创建了一个选中的列表视图,其中一列是可编辑的文本框。 I want to enable or disable the subitem on each row according to the state of the checkbox, but can't find a property or a way to access the subitem's edit state. 我想根据复选框的状态启用或禁用每行上的子项目,但是找不到属性或访问子项目的编辑状态的方法。 I've tried to cast the subitem back to a control, but that didn't work as well. 我试图将子项目投射回控件,但效果不佳。

This is the solution I used. 这是我使用的解决方案。 I hope there's a more elegant one: I created a List of TextBoxes and as I added a textbox to a ListViewItem I also added it to the list. 我希望有一个更好的例子:我创建了一个TextBoxes列表,并且在将文本框添加到ListViewItem时也将它添加到了列表中。 In addition, I added a Tag to each ListViewItem with the TextBox's name. 此外,我还为每个ListViewItem添加了一个具有文本框名称的Tag。 Now, when I check or uncheck a certain row I get the name of the control from the tag via lstItemList.Items[e.Index].SubItems[3].Tag.ToString() and search for it in the list. 现在,当我选中或取消选中某一行时,我可以通过lstItemList.Items [e.Index] .SubItems [3] .Tag.ToString()从标记中获取控件的名称,然后在列表中进行搜索。 I change the Enabled property of the located TextBox. 我更改了找到的TextBox的Enabled属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM