I have written a proof of concept code. The rough sketch is like this:
void SBO_Application_ItemEvent1(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
{
int formType = -111;
SAPbouiCOM.Form oInvoiceForm;
SAPbouiCOM.Item oItem;
SAPbouiCOM.Matrix oMatrix;
SAPbouiCOM.Columns oColumns;
SAPbouiCOM.Column oBarcodeCol, oItemNoCol;
SAPbouiCOM.Cells oCells;
SAPbouiCOM.Cell oCell;
SAPbouiCOM.EditText oBarcodeEditText, oEditText;
string barcodeValue = "";
BubbleEvent = true;
formType = pVal.FormType;
if (formType == 133 //AR Invoice
&& pVal.ItemUID.Equals("38") //Matrix / Grid
&& pVal.EventType == SAPbouiCOM.BoEventTypes.et_VALIDATE
&& pVal.Before_Action == false)
{
//SBO_Application.MessageBox("Event: " + pVal.EventType.ToString()
// + ", Form Unique ID: " + pVal.FormUID
// + Environment.NewLine
// + "Form Type: " + formType.ToString()
// + ", Form Mode: " + pVal.FormMode.ToString()
// + ", Form TypeEx: " + pVal.FormTypeEx
// + ", Item Id: " + pVal.ItemUID
// + ", Col Id: " + pVal.ColUID
// + ", Row: " + pVal.Row.ToString()
// + Environment.NewLine
// + "BEFORE ACTION: " + pVal.Before_Action.ToString()
// , 1, "Ok", "", "");
if (pVal.ColUID.Equals("4")) //Barcode Column
{
oInvoiceForm = SBO_Application.Forms.GetFormByTypeAndCount(formType, pVal.FormTypeCount);
oMatrix = (SAPbouiCOM.Matrix)oInvoiceForm.Items.Item(pVal.ItemUID).Specific;
oBarcodeCol = oMatrix.Columns.Item(pVal.ColUID);
oBarcodeEditText = (SAPbouiCOM.EditText)oBarcodeCol.Cells.Item(pVal.Row).Specific;
barcodeValue = oBarcodeEditText.Value;
if (!string.IsNullOrEmpty(barcodeValue))
{
oItemNoCol = oMatrix.Columns.Item("1");
oEditText = (SAPbouiCOM.EditText)oItemNoCol.Cells.Item(pVal.Row).Specific;
//Check if Item exists in any of the previous rows
//If item exists, increase the qty in existing row
//Set current row item to BLANK
//This causes calls to the Validate event of each cell. How to avoid this?
oBarcodeEditText.Value = "";
oBarcodeEditText.String = "";
oEditText.Value = "";
//This causes exception
//oMatrix.SetLineData(pVal.Row);
//But by this time, the other column values like Quantity, Warehouse etc are already set for this row
//Do I need to clear them cell by cell?
//Is it possible to prevent setting of the other cell values, instead of removing them after they are set?
//This works, but screen flickers
oMatrix.DeleteRow(pVal.Row);
}
}
}
}
I am facing the following issues in the code:
1. When I remove the value in the Bar Code and Item No. column through code, it causes call to the Validate events of each cell. How to avoid this?
2. The other column values like Quantity, Warehouse etc are already set for this row by SAP.
2a. Is it possible to prevent setting of the other cell values, instead of removing them after they are set?
2b. If it can not be avoided, do I need to clear them cell by cell, or should I use the DeleteRow method. If I use the DeleteRow method, the screen flickers briefly.
Thanks.