|
-
Mar 30th, 2003, 06:06 PM
#1
Thread Starter
Lively Member
Selecting an item in a listview
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?
-
Mar 30th, 2003, 07:11 PM
#2
Lively Member
Re: Selecting an item in a listview
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
-
Mar 30th, 2003, 08:53 PM
#3
Hyperactive Member
'something like this?
Code:
ListView1.ListItems(2).Selected = True
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
-
Mar 31st, 2003, 07:07 AM
#4
Thread Starter
Lively Member
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.
-
Mar 31st, 2003, 07:24 AM
#5
Thread Starter
Lively Member
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.
-
Feb 25th, 2005, 10:58 AM
#6
New Member
Re: Selecting an item in a listview
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.
Code:
Me.listView1.Items(0).Selected = True
Me.listView1.HideSelection = False
Console.Write(listView1.SelectedItems(0).Selected.ToString)
This will fail with: "Specified argument was out of the range of valid values. Parameter name: index".
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.
Code:
listView1_Click(listView1, System.EventArgs.Empty)
Regards Eamon.
PS: I’m using VB.net web forms 2003.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|