I have a listview displaying some items in detail mode and i would like the second item to be already selected. Anyone know how to do this?
Printable View
I have a listview displaying some items in detail mode and i would like the second item to be already selected. Anyone know how to do this?
Quote:
Originally posted by Wallabie
I have a listview displaying some items in detail mode and i would like the second item to be already selected. Anyone know how to do this?
Code:listbox1.selectedindex = 1
'something like this?
Code:ListView1.ListItems(2).Selected = True
Hmmm, the first one is for a listbox not a listview.
The second one looks like the old VB6 way which i don't think works in .NET because i don't see a ListItems in the intel-sense popup box.
Dont you just hate it when this happens?
I've just been mucking around and found it myself now...for those that would like to know, this partialy works, the row itself is grey-ed out and not highlighted though in the first instance on load but after that it is highlighted ok.
Code:Me.listView1.Items(1).Selected = True
Me.listView1.HideSelection = False
Hope this helps others looking for this.
Hi all
Wallabie, you are right. That worked a treat, thank you.
I still think that there's a problem with the listview control though. If you add the following line after your code you will find that the control does not contain any selected items.
This will fail with: "Specified argument was out of the range of valid values. Parameter name: index".Code:Me.listView1.Items(0).Selected = True
Me.listView1.HideSelection = False
Console.Write(listView1.SelectedItems(0).Selected.ToString)
If anyone can explain why, or what i am doing wrong, I would be very grateful. What i'm trying to do is call the click event for the listview after i set it default selection. This works if I click the item, but errors when loading.
Regards Eamon.Code:listView1_Click(listView1, System.EventArgs.Empty)
PS: I’m using VB.net web forms 2003.