ComboBox.SelectedIndexChanged

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need help!! I'm using the selectedindexchanged event of a combobox to fill
another combobox according to the selected value of the first one, but the
combobox_selectedindexchanged happens twice so the same routine of searching
data occurs twice!!! So my application takes twice the time it should take. I
debug that part of my application, and when it reaches the end sub of that
subrutine the first time, the event takes place again, so the control doesn't
return to the function it called as soon as it finishes the sub but after the
second time is done.
What can I do?? Help me please, I would really appreciate it.
 
Hi, it's a winform. I have two comboboxes: cmbLines and cmbProducts. When you
choose one line you search for the products of that line and you display them
in the cmbproducts.
Here is the code:

Private Sub cmbLines_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbLines.SelectedIndexChanged
Dim ObjProducts As BaseProducts
Dim DtProducts As DataTable

ObjProduct = New BaseProducts(ConSql)
DtProducts = New DataTable
DtProducts = ObjProducts.BringProducts(cmbLines.SelectedValue)
cmbProducts.DataSource = DtProducts
ObjProducts.Dispose()
End Sub

Private Sub cmbProducts_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles cmbProducts.SelectedIndexChanged
Dim ObjBaseProducts As BaseProducts
Dim ObjProduct As CProduct

ObjBaseProducts = New BaseProducts(ConSql)
ObjProduct = New CProduct

ObjProduct =
ObjBaseProducts.BringProductDetail(cmbProductos.SelectedValue)
lblCodig.Text = ObjProduct.Cod
lblName.Text = ObjProduct.Name
lblExis.Text = ObjProducto.Exist
lblPrice.Text = ObjProducto.Price
lblVencDate.Text = Format(ObjProduct.VencDate, "dd/M/yyyy")
lblUnitBox.Text = "C: " & ObjProduct.BoxQty
ObjBaseProducts.Dispose()
End Sub

When cmbProducts.DataSource = DtProducts happens, it goes to
cmbProducts_SelectedIndexChanged but when it reaches the
cmbProducts_SelectedIndexChanged's end sub it goes again to the beginnig of
that routine.

I don't understand. Please help me. Thanks.
 
Hi, it's a winform. I have two comboboxes: cmbLines and cmbProducts. When you
choose one line you search for the products of that line and you display them
in the cmbproducts.
Here is the code:

Private Sub cmbLines_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbLines.SelectedIndexChanged
Dim ObjProducts As BaseProducts
Dim DtProducts As DataTable

ObjProduct = New BaseProducts(ConSql)
DtProducts = New DataTable
DtProducts = ObjProducts.BringProducts(cmbLines.SelectedValue)
cmbProducts.DataSource = DtProducts
ObjProducts.Dispose()
End Sub

Private Sub cmbProducts_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles cmbProducts.SelectedIndexChanged
Dim ObjBaseProducts As BaseProducts
Dim ObjProduct As CProduct

ObjBaseProducts = New BaseProducts(ConSql)
ObjProduct = New CProduct

ObjProduct =
ObjBaseProducts.BringProductDetail(cmbProductos.SelectedValue)
lblCodig.Text = ObjProduct.Cod
lblName.Text = ObjProduct.Name
lblExis.Text = ObjProducto.Exist
lblPrice.Text = ObjProducto.Price
lblVencDate.Text = Format(ObjProduct.VencDate, "dd/M/yyyy")
lblUnitBox.Text = "C: " & ObjProduct.BoxQty
ObjBaseProducts.Dispose()
End Sub

When cmbProducts.DataSource = DtProducts happens, it goes to
cmbProducts_SelectedIndexChanged but when it reaches the
cmbProducts_SelectedIndexChanged's end sub it goes again to the beginnig of
that routine.

I don't understand. Please help me. Thanks.
 
Back
Top