我试图以编程方式检查一个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 = TrueAll 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 = TrueYou should use the Checked property to check the item(s) you'd like:
lvVorschlag.Items(0).Checked = True更多推荐
发布评论