Validation within a Combobox


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Great! Thanks!

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It really depends on what I am trying to do, but I generally use the SelectedIndexChanged event more than the SelectedValueChanged since certain errors may have to be trapped on the SelectedValue changed if the combo has not yet been populated, loaded, etc. depending on instatiation orders.  Using the SelectedIndexChanged generally reduces the number of "holes" that have to be plugged.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Geoff, Trent,

Thanks a lot.  This is an interesting approach on how to handle this situation and actually I ended up using the same concept for another case in a DropDown event and it worked just fine.

One more clarification for the combobox, which is the preferable event to handle in a validation case like this, the SelectedIndexChanged or SelectedValueChanged event?

I tried both with the _FormIsLoading approach and they both worked, but I like to be consistent with my coding and be clear as to which event to use for the same common validation.



Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, there are a couple of things that you can do here.  First, you probably have your code in teh right place, just add a _Loading private to your form that gets set in th eOnLoad of the form to prevent the issue.

For example, just create an _Loading private that is initially set to True.  Then in the OnLoad of the form, set this to False.  In the top of the SelectedIndexChanged, exit if this is set:

If _IsLoading Then Exit Sub

There are a number of other ways to get around this as well by just taking Nulls or possible invalid calls into account.  For example, if the BO is being called out of order, then use the InitializationPriority on the BO...y9ou may also want to change the population of one of the controls (if this depends on another) to manual instead of FormLoad, etc.

Geoff Hirst
Geoff Hirst
StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)
Group: Forum Members
Posts: 123, Visits: 3.5K
Hi Edhy,

I have had exactly what you are talking about in the past. To overcome it I have created a form level boolean variable that I set to true at the start of the form load, then false when the form load is over.

Then in my various events that fire during the form load, such as the one you describe, I put the line

IF _IsLoading = true then exit sub

---- THE GOTCHA

This method has worked for me in some place, and come back and bitten me in others.

What might work better, and I have done this also, is if your combo box is bound to a BO, maybe look at using the propertychanged events of the BO and running your code from there.

Best of luck

Geoff.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
In a childform dialog, I have a textbox txtItemPrice that needs to be updated from a combobox items lookup, I have the following code in the combobox.SelectedIndexChanged:

Private Sub cboItemName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboItemName.SelectedIndexChanged

     '-- Look the item price and if found and there is a current price, ask

     ' the user if he/she wants to overwrite the Item Price.

     If Me.BizItems_Lookup.Count > 0 Then

          If Me.BizItems_Lookup.SeekToPrimaryKey(Me.bizSC_AppliancesItems1.FK_Items) Then

               If Me.bizSC_AppliancesItems1.ItemPrice <= 0 Then

                    Me.bizSC_AppliancesItems1.ItemPrice = Me.BizItems_Lookup.ItemPrice

               Else

                    If Me.ShowMessageByKey("ApplianceItems_OverwriteItemPrice", Me.bizSC_AppliancesItems1.ItemPrice, Me.BizItems_Lookup.ItemPrice) = MicroFour.StrataFrame.Messaging.MessageFunctionType.Yes Then

                         Me.bizSC_AppliancesItems1.ItemPrice = Me.BizItems_Lookup.ItemPrice

                    End If

               End If

          End If

          Me.bizSC_AppliancesItems1.Refresh("ItemPrice")

     End If

End Sub

The problem is that when the ChildFormDialog is being loaded, the cboItemName_SelectedIndexChanged method is being fired several times, even when the form has not even shown.  In VFP I would simply put the code in the combobox.Valid(), how to get the same effect as the VFP combobox.Valid() or what event should be used in the combo in this scenario ?

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search