[英]I'm using C# in studio code, how to get content from checked column in listview?
I'm using C# in studio code, now I created a form with listview, I added columns and checkboxes in the listview, and I want to ask how to extract the content of the first column from the checked row.我在工作室代码中使用 C#,现在我用列表视图创建了一个表单,我在列表视图中添加了列和复选框,我想问一下如何从选中的行中提取第一列的内容。
I tried to search for ways online but none of them work I guess..我试图在网上搜索方法,但我想它们都不起作用。
To be able to extract data you can try the following:为了能够提取数据,您可以尝试以下操作:
First, you need to get a reference to the listview control.首先,您需要获得对列表视图控件的引用。 You can do this by using the FindControl method or by using the ID property of the listview.您可以使用 FindControl 方法或使用列表视图的 ID 属性来执行此操作。
Next, you can use the CheckedItems property of the listview to get a collection of all the checked rows.接下来,您可以使用列表视图的 CheckedItems 属性来获取所有选中行的集合。
You can then use a foreach loop to iterate through each checked row然后,您可以使用 foreach 循环遍历每个选中的行
in the collection.在集合中。
For each checked row, you can use the SubItems property of the对于每个选中的行,您可以使用
ListViewItem to get a collection of all the subitems (columns) in the row. ListViewItem 获取行中所有子项(列)的集合。
You can then use the Text property of the first subitem (column) in the collection to get the content of the first column.然后,您可以使用集合中第一个子项(列)的 Text 属性来获取第一列的内容。
Short example:简短示例:
foreach (ListViewItem item in listview1.CheckedItems)
{
string firstColumnText = item.SubItems[0].Text;
// Do something with the firstColumnText value here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.