Select ListboxItem [solved]

Posts 1–12 of 12 · Page 1 of 1
Select ListboxItem [solved]
Code:
Dim val As Integer = 0
     val = ListBox1.Items.Count
     ListBox1.SelectedItem = val
Im using that code . . . But, It doesnt work , I want to select the last item of the listbox using a variable to later modifie it.

thanks
You can select the last item by doing ListBox1.Items.Count - 1.
Use the "SelectedIndex" property to change which item is selected. Indices start at 0 and go to the size of the collection - 1.
Dim val As Integer = 0
val = ListBox1.Items.Count -1
ListBox1.SelectedItem = val
Quote Originally Posted by Lyoto Machida View Post
Dim val As Integer = 0
val = ListBox1.Items.Count -1
ListBox1.SelectedItem = val
I think you mean:

[highlight=vb.net]
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
[/highlight]
Quote Originally Posted by Jason View Post


I think you mean:

[highlight=vb.net]
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
yeah
i was just thinking on the -1
thanks solved.
Marked solved. No more posting unless absolutely necessary.
Code:
 val = ListBox1.Items.Count - 1
                ListBox1.SelectedIndex = val
I need to make a timer that the selected index Is 9 then 8 then 7 . . . etc

Code:
ListBox1.SelectedIndex = val - 1
But that code dont work
[highlight=vb]
ListBox1.SelectedIndex = ListBox1.SelectedIndex.ToString - 1
[/highlight]
Quote Originally Posted by willrulz188 View Post
[highlight=vb]
ListBox1.SelectedIndex = ListBox1.SelectedIndex.ToString - 1
[/highlight]
While the logic is correct, why the hell did you convert it to string?

[highlight=vb.net]
ListBox1.SelectedIndex -= 1
[/highlight]

Would work.
thanks

/msgtshrt
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?