cancel
Showing results for 
Search instead for 
Did you mean: 

Matrix Validate After event infinite loop

ens_
Active Participant
0 Kudos

Greetings,

I have a Matrix Validate After event which results in infinite loop sometimes. Sometimes it executes correctly some other times i loops until death. Any ideas why this happens and if there is something i am not currently handling?

I add dates on the top right matrix and columns on the bottom matrix should unlock and lock when i remove the date

private void Matrix0_ValidateAfter(object sboObject, SAPbouiCOM.SBOItemEventArg pVal)
        {
            switch (pVal.Row)
            {
                case 1:


                   if( ((SAPbouiCOM.EditText)(Matrix0.Columns.Item(1).Cells.Item(pVal.Row).Specific)).Value.ToString() != "")
                    Matrix1.Columns.Item(3).Editable = true;
                   else


                       Matrix1.Columns.Item(3).Editable = false;
                   EditText1.Item.Click(SAPbouiCOM.BoCellClickType.ct_Regular);


                    break;
                case 2:


                    if (((SAPbouiCOM.EditText)(Matrix0.Columns.Item(1).Cells.Item(pVal.Row).Specific)).Value.ToString() != "")
                        Matrix1.Columns.Item(4).Editable = true;
                    else
                        Matrix1.Columns.Item(4).Editable = false;
                    EditText1.Item.Click(SAPbouiCOM.BoCellClickType.ct_Regular);
                    break;
ens_
Active Participant

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor

Hi Varnavas,

The Validate event is triggered every time a control is "about to sync data with the data source". Action like clicking on another control will trigger the validate event on the current control.

One way to stop this from happening is to temporarily disable all events during your handling of the validate event:

public void AfterValidateHandler(ItemEvent e)
{
var currentEventFilters = application.GetFilter();
application.SetFilter(null);
// do your actions here
application.SetFilter(currentEventFilters);
}

Pedro Magueija

LinkedIn | Twitter | Blog

ens_
Active Participant
0 Kudos

I removed the Click event on the textbox. Loop occurs when i erase something i have written in the matrix cell and click tab. When i am writing data or changing from X to Y it is ok. The problem is when you completely remove the data from a single cell

pedro_magueija
Active Contributor
0 Kudos

Hi Varnavas,

If it's looping you can (using the debugger) see exactly where it triggers the validate again. Note that click is just one type of action that triggers the validate, if you write to another cell, click a button, focus another control, etc... all these will trigger it as well.

Make sure that in your that in your Matrix0_ValidateAfter you are not performing any operation that will trigger another validate.

Pedro Magueija

LinkedIn | Twitter | Blog

ens_
Active Participant
0 Kudos

Still it does not make sense. Here is what happens:

1) i enter a value in the cell i click tab and everything is fine.

this ←code executes:

if( ((SAPbouiCOM.EditText)(Matrix0.Columns.Item(1).Cells.Item(pVal.Row).Specific)).Value.ToString() != "")
Matrix1.Columns.Item(3).Editable = true; ←←←←←←←
else
Matrix1.Columns.Item(3).Editable = false;

2) i don't enter a value in the cell i click tab everything is fine

this ← code executes

if( ((SAPbouiCOM.EditText)(Matrix0.Columns.Item(1).Cells.Item(pVal.Row).Specific)).Value.ToString() != "")
Matrix1.Columns.Item(3).Editable = true;
else
Matrix1.Columns.Item(3).Editable = false; ←←←←←←←

3) i enter a value in the cell i click tab and up until here its ok. i go back to the cell, erase the data click tab and it loops infinitely on the ELSE statement why? since in scenario 2 it executes normally. disabling a column of another matrix triggers validation on a different matrix?

pedro_magueija
Active Contributor
0 Kudos

Hi Varnavas,

Have you used the EventLogger tool to check the event chain?

There you can see what and when the events are being fired. Then you can adjust your code accordingly.

Pedro Magueija

LinkedIn | Twitter | Blog

Answers (3)

Answers (3)

ens_
Active Participant

After having remote aid from Pedro Magueija we managed to solve this using filters. Just a side not, its not the first time Pedro does something like this. He's an SDK Dictionary. any page you flip you learn something 🙂

ens_
Active Participant
0 Kudos

After submitting my code through a ticket to SAP Development, they returned back saying that we discovered a bug in the current event (matrix validate after which has now been marked as "to be fixed with a patch". So currently work with what Pedro suggested until we hear something new.

ens_
Active Participant
0 Kudos

Note to my above code, the part

 EditText1.Item.Click(SAPbouiCOM.BoCellClickType.ct_Regular);

I was removed since it was causing worse things. You can see the behavior here