3

I'm trying to read from a Matrix. The code that I have until now is:

SAPbouiCOM.Matrix matrix = (SAPbouiCOM.Matrix SBO_Application.Forms.ActiveForm.Items.Item("38").Specific;              
SAPbouiCOM.Column col = matrix.Columns.Item("1") ;
SAPbouiCOM.Cells cells = col.Cells;
String cell = cells.Item(2).Specific.ToString();
String f = cell.ToString();

None of the Strings (cell and f) give me the value of the cell...

Any Idea?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Miguel Ribeiro
  • 31
  • 1
  • 1
  • 3

5 Answers5

5

@Miguel try this code

  string ColId   = "1"; //Set The Column Name to read
  Int32  Row     = 2; //Set the Row to Read
  Matrix oMatrix =(Matrix)SBO_Application.Forms.ActiveForm.Items.Item("38").Specific; //Get Access to the Matrix
  EditText oEdit =(EditText)oMatrix.Columns.Item(ColId).Cells.Item(Row).Specific; //Cast the Cell of the matrix to the respective type , in this case EditText
  string sValue  = oEdit.Value; //Get the value form the EditText

Miguel additionally check the SAP Business One SDK Forum for any question about SAP B1.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
1

If you need to get data from Matrix :

var cellValue = oMatrix.Columns.Item(Column's Id or Index).Cells.Item(Row's Index).Specific.Value;

But if you need to update matrix value have to cast col to EditText obj like :

var oEdit = (SAPbouiCOM.EditText)oMatrix.Columns.Item(Column's Id or Index).Cells.Item(Row's Index).Specific;
 oEdit.Value = "1";
0
SAPbouiCOM.EditText EditValue;
string strValue;
String ColUId = "col_1"  // Column UID
Int32 Row     = 1        //Row Number
Item item     = form.Items.Item("38");
Matrix matrix = ((Matrix)(item.Specific));
EditValue     = (SAPbouiCOM.EditText)matrix.GetCellSpecific(ColUId, Row );
strValue      = EditValue.Value.ToString().Trim();
JiNish
  • 193
  • 7
0

we can also write the same in following manner. i made this in vb.net

Dim  matrix  as  SAPbouiCOM.Matrix 

matrix =  oForm.Items.Item("38").Specific 


dim f as string = matrix .Columns.Item("3").Cells.Item(2).Specific.value.tostring

Here cell number is 2 and column number is 3 . so f value will be 2nd row of 3 column value.

bluish
  • 26,356
  • 27
  • 122
  • 180
Rajmohan
  • 46
  • 2
0

If you are trying to read some column values from a form it would be way easier to use SQL queries. This is what I do.

 string firmenname = "";
 string ort = "";
 string plz = "";
 string strasse = "";
 SAPbobsCOM.Recordset mRs1 = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
 string sqlstring = " select top 1 street, zipcode, city, country, address from CRD1 where cardcode = '" + codeid + "' and adrestype ='B' ";
 mRs1.DoQuery(sqlstring);
 while (!mRs1.EoF)
 {
 strasse = mRs1.Fields.Item("street").Value.ToString();
 ort = mRs1.Fields.Item("city").Value.ToString();
 plz = mRs1.Fields.Item("zipcode").Value.ToString();
 firmenname = mRs1.Fields.Item("address").Value.ToString();
 mRs1.MoveNext();
 }

I kinda had the same question as you. But after I came up with this idea it was so easy to read values from any form with number of columns. All you have to do is "View -> System Informations" and know in which database table, the values are stored. Then write your desired SQL query.

Hope this helps you!

Isuru
  • 430
  • 5
  • 21