none
In einer ListBox zum nächsten Eintrag wechseln per Buttonklick RRS feed

  • 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
    Sonntag, 28. Februar 2010 18:39

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
    Sonntag, 28. Februar 2010 19:07
  • Hallo Dominik,

    geht ebenfalls über SelectedIndex und die RemoveAt Methode:
    If ListBox1.SelectedIndex >= 0 Then
        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    End If
    
    Gruß Elmar
    Sonntag, 28. Februar 2010 19:39

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
    Sonntag, 28. Februar 2010 19:07
  • Danke Mathias!

    Jetzt benötige ich nur noch das man das Makierte Objekt entfernen kann.

    LG
    Dominik
    Sonntag, 28. Februar 2010 19:22
  • Hallo Dominik,

    geht ebenfalls über SelectedIndex und die RemoveAt Methode:
    If ListBox1.SelectedIndex >= 0 Then
        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    End If
    
    Gruß Elmar
    Sonntag, 28. Februar 2010 19:39
  • Danke euch.
    Meine Problem sind jetzt gelöst und das Programm (Media Player) funktioniert einwandfrei!

    LG Dominik
    Sonntag, 28. Februar 2010 20:38