INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SelectIndex on Listbox isn't working

SelectIndex on Listbox isn't working

(OP)
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

RE: SelectIndex on Listbox isn't working

(OP)
Please ignore this thread as I have now resolved it myself!

RE: SelectIndex on Listbox isn't working

Hi Haliarse, What was the cause of your problem? Lots of us would like to learn in case we come across this too.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close