Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Bound ComboBox SelectedIndexChanged Event not updating other bound controls timely?

$
0
0

Help.

I am developing a program that is essentially a 'product configurator'.  On the 'product selection' form, I have two DataAdapters/DataSets connected to the form.  One, is for the product options, the other for the ordering.

What I am doing, is selecting an item in a bound ListBox control, the 'PartNumber' field of the DataSet. which then updates all the other bound controls (textboxes, and checkboxes), for the same DataSet.  Then I have a Sub (UpdateControls) that enables/disables other controls (unbound) from which the user selects options for the Part to Order.  Then I take these options, create an order, then commit those changes back to the Order DataSet.

I use the ListBox control's SelectedIndexChanged event to Call the UpdateControls Sub, which works great.  The code basically looks like this:

    Private Sub lstPartNumber_SelectedIndexChanged(ByVal sender As System.Object, _
         ByVal e As System.EventArgs) Handles lstPartNumber.SelectedIndexChanged

        ' THIS ROUTINE UPDATES THE CONFIGURATOR SO ONLY AVAILABLE OPTIONS ARE ENABLED

            Call UpdateControls()

    End Sub

The issue is that I would prefer to have the user select from a drop down list vs. scrolling through a ListBox.  So, I made a ComboBox control, set it with the same databindings, and called the ComboBox's SelectIndexChanged event to fire the same subroutine.  But this does not work correctly unless I select the item in the ComboBox twice (select once, then select a second time).  What is happening is that the other bound controls are not updating to the current record selected in the ComboBox the same as with the ListBox.

So, after trapping each step, I have found that the problem is with the timing of the SelectedIndexChanged event between the two controls, not the binding, or the Subroutine.  It appears that the event's order happens like this:

ListBox Control:

* User selects item in control (mouse click)

* Other bound controls update

* SelectedIndexChange event fires

* UpdateControls Subroutine fires

* Controls are updated to match the current record

ComboBox Control:

* User selects item in control (mouse click)

* SelectedIndexChange event fires

* UpdateControls Subroutine fires

* Controls are updated to match the last/old record

* Other bound controls update

Is there another event I should be using that will fire after the associated bound controls are updated?  I just don't know why these should fire at different times.

TIA


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>