again problem with listbox :(
i really tried to find help from google but i couldn't
My problem is this :
I have 3 listboxes
quantity , MenuItem , Price
then user must enter data into them
then when user clicks on one item in one listbox the same index items from 2 other listboxes must also be selected

problem now begins
there must be a button to Clear these 3 selected items

what happens in my code is that
i wrote this :

Private Sub lstQuantity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstQuantity.SelectedIndexChanged

        btnRemoveLine.Enabled = True

        lstMenuItem.SelectedIndex = lstQuantity.SelectedIndex
        lstPrice.SelectedIndex = lstQuantity.SelectedIndex

    End Sub

    Private Sub lstMenuItem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstMenuItem.SelectedIndexChanged
        btnRemoveLine.Enabled = True
               lstQuantity.SelectedIndex = lstMenuItem.SelectedIndex
        lstPrice.SelectedIndex = lstMenuItem.SelectedIndex
    End Sub

    Private Sub lstPrice_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstPrice.SelectedIndexChanged
        btnRemoveLine.Enabled = True
        lstQuantity.SelectedIndex = lstPrice.SelectedIndex
        lstMenuItem.SelectedIndex = lstPrice.SelectedIndex
    End Sub

then the code for btnRemoveLine is this :


If lstMenuItem.SelectedIndex <> -1 And lstPrice.SelectedIndex <> -1 And lstQuantity.SelectedIndex <> -1 Then
           End If

when first it removes the SelectedItem in lstPrice it goes again to Private Sub lstPrice_SelectedIndexChanged and again sets the SelectedIndex so the 2 other list boxes will be unselected because Selected Index in all 3 list boxes are equal and when it removes one of them the 2 other indexes will be equal to -1

please let me know if i didn't explain the problem well

I need urgent help :(
tnQ all

6 Years
Discussion Span
Last Post by Oxiegen

In your code for btnRemoveLine, do this:

If lstMenuItem.SelectedIndex <> -1 AndAlso lstPrice.SelectedIndex <> -1 AndAlso lstQuantity.SelectedIndex <> -1 Then
       Dim index As Integer = lstPrice.SelectedIndex
End If
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.