简体   繁体   English

我在工作室代码中使用 C#,如何从列表视图中的选中列中获取内容?

[英]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.

相关问题 如何使用Visual Studio和C#Win Forms使Column AutoSize功能与ListView一起使用 - How do i get Column AutoSize functionality to work with ListView, using Visual Studio and C# Win Forms C#:如何从数据库的最后一行获取数据? 我在Visual Studio 2017中使用 - C#: How to get data from the last row in database? I'm using in visual studio 2017 我如何在使用C#的情况下在代码中签入带复选框的'tr's ID - How do I get 'tr's ID with checkbox checked in code behind using C# 如何通过简单的代码从C#的同一面板中的RadioButtons组中获取Checked RadioButton? - How Can I get by simple code the Checked RadioButton From Group of RadioButtons Located in same panel in C#? 从ListView C#WinForms获取最后检查的项目 - get last checked item from listview c# winforms 如何使用c#wpf Visual Studio 2013从listview覆盖样式? - How do I Override styling from listview using c# wpf Visual studio 2013? 如何在C#WPF中从Listview获取所有选中的选定项目 - How to get all checked selected items from Listview in c# WPF 我需要在 Visual Studio 中使用代码 C# 从表值函数中获取 SQL 中的数据集 - I need to get the Dataset from SQL from Table Valued Function using code C# in visual studio 我正在使用 C# Visual Studio forms。 如何将 Program.cs 中的 var 转换为 VS 表单? - I'm using C# Visual Studio forms. How do I get a var in Program.cs to a VS form? 从Listview列c#/ wpf中提取内容 - Extract content from a Listview column c#/wpf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM