以编程方式检查ListView中的复选框(Programmatically check a checkbox in ListView)

编程入门 行业动态 更新时间:2024-10-22 15:43:47
以编程方式检查ListView中的复选框(Programmatically check a checkbox in ListView)

我试图以编程方式检查一个ListView的复选框(使用VB和.NET 4)。

ListView lvVorschlag已经在设计器中创建,还有三个元素。 然后我执行以下操作:

Dim lviOptimal As New ListViewItem("Optimal") lviOptimal.SubItems.Add(...) 'several SubItems are added lvVorschlag.Items.Add(lviOptimal) lvVorschlag.Items(0).Selected = True

所有SubItems都已正确添加,行lvVorschlag.Items(0).Selected = True不会给我一个错误。 但没有检查。 任何想法为什么?

注意:我也试过使用lvVorschlag.Items("Optimal").Selected = True但它给了我一个错误,说这个对象是Nothing 。 太糟糕了,用名字来指代会更容易。

I am trying to programmatically check a checkbox of a ListView (using VB & .NET 4).

The ListView lvVorschlag has been created in the designer, along with three elements. I then do the following:

Dim lviOptimal As New ListViewItem("Optimal") lviOptimal.SubItems.Add(...) 'several SubItems are added lvVorschlag.Items.Add(lviOptimal) lvVorschlag.Items(0).Selected = True

All the SubItems are correctly added and the line lvVorschlag.Items(0).Selected = True does not give me an error. But nothing is checked. Any idea why?

Note: I also tried with lvVorschlag.Items("Optimal").Selected = True but it gives me an error saying that this object is Nothing. Too bad, referring by name would have been easier.

最满意答案

您应该使用Checked属性来检查您想要的项目:

lvVorschlag.Items(0).Checked = True

You should use the Checked property to check the item(s) you'd like:

lvVorschlag.Items(0).Checked = True

更多推荐

本文发布于:2023-04-28 04:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   方式   ListView   checkbox   Programmatically

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!