You are currently viewing How to Select a row in System Matrix(SAPbouiCOM.Matrix) in SAP Busines One?
SAP Business One

How to Select a row in System Matrix(SAPbouiCOM.Matrix) in SAP Busines One?

You can call SelectRow() Method of System Matrix to select a particular row in System Matrix.

Please check the following example.

public void SBO_Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
  {
    if ((pVal.ItemUID == "Matrix1") & (pVal.EventType != BoEventTypes.et_CLICK))
        {
                        try
                        {
                            SAPbouiCOM.Form oForm1 = SBO_Application.Forms.ActiveForm;
                            Item oItemmatrix = oForm1.Items.Item("Matrix1");
                            Matrix oMatrix = ((SAPbouiCOM.Matrix)(oItemmatrix.Specific));
                            oMatrix.SelectionMode = BoMatrixSelect.ms_Auto;
                            oMatrix.SelectRow(pVal.Row, true, false);
                        }
                        catch(Exception ex) { }
                        
        }
  }

Please Note: before calling oMatrix.SelectRow() method we should set selection mode to auto. like below

oMatrix.SelectionMode = SAPbouiCOM.BoMatrixSelect.ms_Auto;

oMatrix.SelectRow(pVal.Row, true, false);

To get the column value you can code like below

public void SBO_Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
  {
    if ((pVal.ItemUID == "Matrix1") & (pVal.EventType != BoEventTypes.et_CLICK))
        {
                        try
                        {
                            SAPbouiCOM.Form oForm1 = SBO_Application.Forms.ActiveForm;
                            Item oItemmatrix = oForm1.Items.Item("Matrix1");
                            Matrix oMatrix = ((SAPbouiCOM.Matrix)(oItemmatrix.Specific));
                            string COLVALUE = Convert.ToInt32(((SAPbouiCOM.EditText)oMatrix.Columns.Item("COLID").Cells.Item(pVal.Row).Specific).Value.ToString());
                            oMatrix.SelectionMode = BoMatrixSelect.ms_Auto;
                            oMatrix.SelectRow(pVal.Row, true, false);
                        }
                        catch(Exception ex) { }
                        
        }
  }

Please Note: Replace COLID with your ColumnName.