Skip to Content
0

BubbleEvent in Validation Handler has no effect

Apr 11 at 12:30 PM

26

avatar image

Hello Experts,

I am trying to validate a value the user enters in a cell of a grid. If I add the eventHandler via Grid0.Columns.Item("ColId").ValidateBefore += ValidationHandler, everything works fine. But for some reason the eventHandler gets lost over time, although the form is still active. So I tried to add a EventHandler to the SBO_Application.ItemEvent, and remove it when the form gets closed. But now the BubbleEvent = false has no effect on the Grid behaviour (a invalid value is entered, but the user can still change cell focus).

Thanks in advance and best regards!

 private void SBO_Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
        {
            BubbleEvent = true;
            if
            (
                    pVal.BeforeAction
                &&  pVal.ItemUID == Grid0.Item.UniqueID
                &&  pVal.FormUID == UIAPIRawForm.UniqueID
                &&  pVal.Row >= 0
                &&  pVal.ColUID == COLID_VALUE
                &&  pVal.EventType == SAPbouiCOM.BoEventTypes.et_VALIDATE
                &&  pVal.ItemChanged
            )
            {
                SetParameter(pVal.Row, out BubbleEvent);
            }
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Edy Simon Apr 12 at 12:35 AM
1

Hello,

Grid0.Columns.Item("ColId").ValidateBefore += ValidationHandler

This will work as long as the Grid(0).Columns.Item("ColId") lives in the memory.
Once the GC collected this object, this reference to the handler will become invalid.
Also note that this can lead to a memory leak situation.

To properly handle this event you have a few option:

1. Add the handler to the Grid0 instead of the specific column.
2. If you want to handle the specific column, declare your column as a variable, and add the handler to this variable.

Note that you also need to make sure that the Grid0 or the Column variable lives through out your form's life, so that GC does not collect it.

Regards
Edy


Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks a million, Edy! This sounds reasonable.

0