cancel
Showing results for 
Search instead for 
Did you mean: 

filling data in user matrix

Former Member
0 Kudos

Hi, I have created a user matrix and would like to know how I can fill string type data within the code. i have tried something like this but returns an error about object refernce not set to an instance of an object.. My code is below:

oItem = oForm.Items.Add("Matrix1", SAPbouiCOM.BoFormItemTypes.it_MATRIX)


...add columns

oUserMatrix = oform.Items.Item("Matrix1").Specific

oUserMatrix.Columns.Item("itemcode").Cells.Item(1).Specific.string() = "ABC"

When I try to assign a value to a cell, the error message is thrown. Any advice from you would be appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The code of Alexy should work, there is a little different with your one (see the .string() part at your last line)

But I must agree with Sébastien, I also stringly recommend to use user- or dbdatasources to fill your matrix... That way you are doning with EditText fields is very slow... you can win a lot on performance if you use userdatasources...

Sample (C#)

// Add datasource
UserDataSource dsTXT = MySAPForm.DataSources.UserDataSources.Add("MyDS",BoDataType.dt_SHORT_TEXT, 20);

// Get a object to the matrix and bind the datasource
Matrix MyMatrix = (Matrix)MySAPForm.Items.Item("MyMatrix").Specific;
MyMatrix.Columns.Item("MyColumn").DataBind.SetBound(true, "", "MyDS");

// Add 10 rows
MyMatrix.Rows.Add(10,0);

// Loop through the matrix
for(int i = 1; i <= 10; i++)
{
  // Assign a value to the datasource
  MyDS.ValueEx = "Nice Value";

  // Load the line into the matrix
  MyMatrix.SetLineData(i);
}

Hope it helps...

Answers (2)

Answers (2)

Former Member
0 Kudos

Alan,

you must be sure that the matrix has rows.

oUserMatrix.AddRow

I think it would be better to fill the matrix thru the datasource.

Sebastien

AlexGrebennikov
Active Contributor
0 Kudos

Hi Alan! That should work:

oItem = oForm.Items.Add("Matrix1", SAPbouiCOM.BoFormItemTypes.it_MATRIX)
\...add columns
oUserMatrix = oform.Items.Item("Matrix1").Specific
oEdit = oUserMatrix.Columns.Item("itemcode").Cells.Item(1).Specific
oEdit.string = "ABC"