Feedback

VB - Scrollen in einer Listbox

Veröffentlicht von am 6/15/2011
(0 Bewertungen)
Mit diesem Snippet, können Listboxeinträge nach oben oder unten gescrollt werden.
Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click
    Dim SaveEntryAfter As String
    Dim SaveEntyBefore As String
    
    If Len(Listbox.SelectedItem) > 0 And Listbox.SelectedIndex > 0 Then
        SaveEntryAfter = Listbox.Items.Item(Listbox.SelectedIndex - 1)
        SaveEntyBefore = Listbox.SelectedItem
        Listbox.Items.Item(Listbox.SelectedIndex - 1) = SaveEntyBefore
        Listbox.Items.Item(Listbox.SelectedIndex) = SaveEntryAfter
        Listbox.SelectedItem = SaveEntyBefore
    End If

End Sub

Private Sub cmdDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDown.Click
    Dim SaveEntryBefore As String
    Dim SaveEntyAfter As String
    
    If (Len(Listbox.SelectedItem)) > 0 And Listbox.Items.Count > Listbox.SelectedIndex + 1 Then
        SaveEntryBefore = Listbox.Items.Item(Listbox.SelectedIndex + 1)
        SaveEntyAfter = Listbox.SelectedItem
        Listbox.Items.Item(Listbox.SelectedIndex + 1) = SaveEntyAfter
        Listbox.Items.Item(Listbox.SelectedIndex) = SaveEntryBefore
        Listbox.SelectedItem = SaveEntyAfter
     End If

End Sub
Abgelegt unter Listbox, scrollen.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!