gpt4 book ai didi

c# - 在 ListView 中双击 Item 时获取 SubItem 值

转载 作者:太空狗 更新时间:2023-10-30 00:36:05 26 4
gpt4 key购买 nike

我有一个包含 2 列的 ListView ,当我双击一个项目时,我需要在 TextBox 控件中显示其相应子项目的值。我该怎么做?

我搜索了 Google,但没有返回任何有用的信息,可能是因为我不确定要搜索什么。

谢谢

最佳答案

您想要阅读的 MSDN 链接是 ListViewItemListViewSubItem .
您通过 ListViewItem.SubItems 属性访问 ListView 项的子项最重要的是要记住,第一个子项是指所有者 ListView 项,因此要访问您需要从 1 开始索引的实际子项。这将返回一个 ListViewSubItem 对象,并且您可以通过调用 ListViewSubItem.Text 获取它的文本字符串。


SubItems[0] 为您提供“父级” ListView 项
SubItems[1] 为您提供第一个子项等

快速、讨厌的代码片段

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedIndexCollection sel = listView1.SelectedIndices;

if (sel.Count == 1)
{
ListViewItem selItem = listView1.Items[sel[0]];
textBox1.Text = selItem.SubItems[1].Text;
}
}

希望对你有帮助

关于c# - 在 ListView 中双击 Item 时获取 SubItem 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2891053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com