Skip to Content

Matrix as an input

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. :(

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 02, 2016 at 01:05 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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