vb.net 如何在ListView中获取选中的行项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5791949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:27:35  来源:igfitidea点击:

How to get the selected row items in ListView

vb.netwinforms

提问by Failed_Noob

This is my ListView, Column 1 for ID and Column 2 for Notes

这是我的 ListView,第 1 列用于 ID,第 2 列用于注释

enter image description here

在此处输入图片说明

I have a Multi-Line textbox and a Button Like this

我有一个多行文本框和一个像这样的按钮

enter image description here

在此处输入图片说明

I want to load the selected note on the textbox when the button is clicked. How can I do this ?

我想在单击按钮时在文本框中加载选定的注释。我怎样才能做到这一点 ?

回答by Bala R

You can try something similar to this (you'll have to tweak it for your setup)

您可以尝试类似的操作(您必须针对您的设置进行调整)

If listView.SelectedItems.Count > 0 Then
    textBox.Text = listView.SelectedItems(0).SubItems(1).Text
End If

if you don't like the idea of using column index and if you have your columns setup right then you should be able to do .SubItems("ID").Text

如果您不喜欢使用列索引的想法,并且您的列设置正确,那么您应该能够做到 .SubItems("ID").Text

回答by user274481

the following may work

以下可能有效

For Each item As ListViewItem In ListView1.SelectedItems()
        TextBox1.AppendText(item.Text & ":" & item.SubItems(1).Text & Environment.NewLine)
Next