Benutzer mit den meisten Antworten
In einer ListBox zum nächsten Eintrag wechseln per Buttonklick

Frage
-
Hallo!
Ich hab mal ne kleine Frage zu ListBox.
Wie schaffe ich es das innerhalb der ListBox das nächste Elemt ausgewählt wird? Also dass das Elemt gewechselt wird und das das ausgewählte Elemt aus der ListBox gelöscht wird?
Ich habe auch schon gesucht aber ich finde ums verrecken nichts...
MFG Dominik- Bearbeitet Dominik Klasen Sonntag, 28. Februar 2010 19:18
Antworten
-
Hi Dominik,
das ist einfach:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' nächster Eintrag If ListBox1.SelectedIndex < (ListBox1.Items.Count - 1) Then ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1 End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' vorheriger Eintrag If ListBox1.SelectedIndex > 0 Then ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1 End If End Sub
Grüße,
Mathias- Als Antwort vorgeschlagen OutOfCoffeeException Sonntag, 28. Februar 2010 20:49
- Als Antwort markiert Robert Breitenhofer Montag, 1. März 2010 09:54
-
Hallo Dominik,
geht ebenfalls über SelectedIndex und die RemoveAt Methode:
If ListBox1.SelectedIndex >= 0 Then ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) End If
Gruß Elmar- Als Antwort vorgeschlagen OutOfCoffeeException Sonntag, 28. Februar 2010 20:48
- Als Antwort markiert Robert Breitenhofer Montag, 1. März 2010 09:54
Alle Antworten
-
Hi Dominik,
das ist einfach:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' nächster Eintrag If ListBox1.SelectedIndex < (ListBox1.Items.Count - 1) Then ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1 End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' vorheriger Eintrag If ListBox1.SelectedIndex > 0 Then ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1 End If End Sub
Grüße,
Mathias- Als Antwort vorgeschlagen OutOfCoffeeException Sonntag, 28. Februar 2010 20:49
- Als Antwort markiert Robert Breitenhofer Montag, 1. März 2010 09:54
-
Hallo Dominik,
geht ebenfalls über SelectedIndex und die RemoveAt Methode:
If ListBox1.SelectedIndex >= 0 Then ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) End If
Gruß Elmar- Als Antwort vorgeschlagen OutOfCoffeeException Sonntag, 28. Februar 2010 20:48
- Als Antwort markiert Robert Breitenhofer Montag, 1. März 2010 09:54