Skip to Content
0

Matrix as an input

Dec 02, 2016 at 09:24 AM

161

avatar image

I wanted to make a Matrix which works as an input form (the user enters rows, then after a button press, I evaluate these rows from the datasource). I loaded a form from Xml which already defines the columns and the matrix, then I attach a DataTable as a datasource in my code. I can add rows in code and insert data to the datasource and flush the content to matrix, which works perfectly (and displayed as I expected), but I just realized the user cannot add rows, If I don't add them previously (with `oDataTable.Rows.Add(2);`). He cannot enter anything and cannot insert a rows to type in If I don't add any rows at all (the matrix is unresponsive). Do I really have to manually handle the Matrix's Item Press events and add rows in my code an such? What If the users want to work with TAB presses, I have to handle them as well? Isn't there a built in method for this?

(I am using SAP 9.2 with UI and DI API C#)

Here is the Matrix object as XML: http://pastebin.com/9D619p0n

And the DataTable: http://pastebin.com/j9Tx8mNe

I bind the Matrix columns to the DS column with

oColumn.DataBind.Bind(...)

Edit.:

Also, I can't even add an empty row. If I don't set the Column values. Simply doing:

oDataTable.Rows.Add(1);
oMatrix.LoadFromDataSource();

Won't add any rows. And one of my Column is an Integer value, so I have to manually set it to a value, becaouse it won't accept an empty string or a null.

Aaand the user can't delete rows with right click-> delete row, because there is no such a menu. :(

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Pedro Magueija Dec 02, 2016 at 01:05 PM
0

Hi Szabolcs,

Short answer: when using the Matrix object you have to handle the adding and removing rows.

Longer answer: the matrix is an older object, therefore it's preferable to use Grid objects instead.

Some situations require the use of a Matrix object, but whenever possible use the Grid instead.

On another note, managing the add/remove rows in the matrix is tricky. If you allow the "Add row" menu to be processed, you'll see a new row but it won't have a corresponding row in the DataTable. That might make things break.

To work around this, when handling menu events for a Matrix, capture them on the "before" stage and set the BubbleEvent to false.

Pedro Magueija

LinkedIn | Twitter | Blog

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Couldn't you only Bind DataTable to Matrices? I need to work with a custom data structure, I only represent it in memory (so not just a single Query). My data is stored in simple model classes (like POJOs in Java) like

class AwdModel {
    public int Id { get; set; }
    ....
}<br>

So I used DataTable as a DataSource and fill it manually.

Edit.: Okay, I tried it, I will use Grid instead of a Matrix (btw, where do you want to use Matrix instead of a Grid?). And for the new row adding, what is the common / best practice? After the user presses enter I can create a new row, but should I check if he tries to click on row below the last one too? Or another "+" button which does this?

0

where do you want to use Matrix instead of a Grid?

When you want to let a UDO manage the "rows". In that case, a Matrix needs to be used, because you can't bind grid columns to a UDO (DBDataSources) (or... I don't know how :S).

And for the new row adding, what is the common / best practice?

I always check how does the client (B1) does it somewhere (marketing document forms, etc...) and I try to make it as similar as possible. I apply this advice to everything (rows, forms, "look and feel", behavior, etc...).

Pedro Magueija

LinkedIn | Twitter | Blog

1