Good Afternoon
I have what appears to me a basic problem but I cannot resolve it and I'm pully my hair out (Something I can ill afford to do!!
Within my Form_Load I am populating my Listbox dynmically with data from a table (Code below, very basic!) The list populates exactly as I would expect!
cmd.CommandText = "SELECT * from Item"
Try
Dim reader As SqlDataReader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
ItemNumber = reader.Item("No_").ToString
ItemNumber = LSet(ItemNumber, 18)
Description = reader.Item("Description").ToString
ListBox1.Items.Add(ItemNumber & "|" & Description)
End While
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
However, I have code that displays the change in selected index which appears to work correctly for the first 2 attempts, but on the 3rd and subsequent, displays the index value from the 2nd selection (I thnk that makes sense!)
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
MsgBox(ListBox1.SelectedIndex)
End Sub
Any advise to stop the impending baldness would be gratefully received!
Many thanks
Steve
I have what appears to me a basic problem but I cannot resolve it and I'm pully my hair out (Something I can ill afford to do!!
Within my Form_Load I am populating my Listbox dynmically with data from a table (Code below, very basic!) The list populates exactly as I would expect!
cmd.CommandText = "SELECT * from Item"
Try
Dim reader As SqlDataReader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
ItemNumber = reader.Item("No_").ToString
ItemNumber = LSet(ItemNumber, 18)
Description = reader.Item("Description").ToString
ListBox1.Items.Add(ItemNumber & "|" & Description)
End While
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
However, I have code that displays the change in selected index which appears to work correctly for the first 2 attempts, but on the 3rd and subsequent, displays the index value from the 2nd selection (I thnk that makes sense!)
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
MsgBox(ListBox1.SelectedIndex)
End Sub
Any advise to stop the impending baldness would be gratefully received!
Many thanks
Steve