Question ListBox blues....

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
So here's the thing. The code below moves items up and down in a listbox and works fine until, it seems, the selected item is below the scrollbar then nothing happens.

Any ideas please?


VB.NET:
Private Sub Reports_ListBoxMoveUp(ByVal LB As ListBox, ByVal DT As DataTable, ByVal DisplayName As String, Optional MasterListBox As ListBox = Nothing)
        Try
            MainForm.Cursor = Cursors.WaitCursor
            Dim StartIndex As Integer = LB.SelectedIndex
            Dim CatID As Integer = 0
            'Update the datasource
            Dim SR() As DataRow
            If DisplayName = "Name" Then
                SR = DT.Select("ID > 0 AND FormID = " & FormID, Nothing)
            Else
                CatID = MasterListBox.SelectedValue
                SR = DT.Select("ID > 0 AND FormID = " & FormID & " AND CatID = " & CatID, Nothing)
            End If
            Dim vString As String = ""
            Dim vLowerID As Integer = 0
            Dim vCurrentID As Integer = 0
            For Each Row As DataRow In SR
                Dim vPos As Integer = Row("Position")
                If vPos = StartIndex - 1 Then
                    vLowerID = Row("ID")
                End If
                If vPos = StartIndex Then
                    vCurrentID = Row("ID")
                End If
            Next
            If Not vLowerID = 0 And Not vCurrentID = 0 Then
                DT.Select("ID = " & vLowerID)(0)("Position") = StartIndex
                DT.Select("ID = " & vCurrentID)(0)("Position") = StartIndex - 1
                Dim vDV As New DataView(DT)
                If DisplayName = "Name" Then
                    vDV.RowFilter = "FormID = " & FormID
                Else
                    vDV.RowFilter = "FormID = " & FormID & " AND CatID = " & CatID
                End If
                vDV.Sort = "Position"
                DT = vDV.ToTable
                vDV = Nothing
                LB.DataSource = DT
                LB.ValueMember = "ID"
                LB.DisplayMember = DisplayName
                LB.SelectedValue = vCurrentID

            End If
        Catch ex As Exception
            EmailError(ex)
            Exit Sub
        Finally
            FormChanged = True
            MainForm.Cursor = Cursors.Default
        End Try
    End Sub
 
Back
Top