Bind Grid to DataTable

Erik van Dongen

Hi,

I want to bind a datatable to a grid. The reason is that the data to display is not comming from the SAP B1 database but out of Oracle.

In the sdk way, i would create a datatable, bind it to the grid and add the rows to it with a fornext loop.

Now i'm trying it by the coresuite framework but i got errors. What is the best way to achieve this? I try it now with the following code but i get the exception "Invalid operation on a loaded datacolumn" While adding the datacolumns (dt.Columns.Add("DebtorId", DataColumn.DataColumnTypes.AlphaNumeric, 50);).

// Complete code
DataTable dt = DataTable.CreateNew("orders");
dt.Columns.Add("DebtorId", DataColumn.DataColumnTypes.AlphaNumeric, 50);
dt.Columns.Add("Type", DataColumn.DataColumnTypes.AlphaNumeric, 50);
dt.Columns.Add("No", DataColumn.DataColumnTypes.AlphaNumeric, 50);
dt.Columns.Add("Price", DataColumn.DataColumnTypes.AlphaNumeric, 50);
form.AddDataTable(dt);

Grid orderGrid = Grid.CreateNew("orderGrid");
orderGrid.DataTable = dt;
orderGrid.Left = 16;
orderGrid.Top = 97;
orderGrid.Width = 534;
form.AddItem(orderGrid);

I also tried:
DataColumn dc = new DataColumn("uniId");
But i got the same error straight away.

Kind regards,
Erik

Marco Schweighauser

Hello Erik,

there seams to be a little bug in the Framework using DataTables. Usually you don't have to use them. Use Grid.ExecuteQuery() instead because this will create the datatable automatically (only works for the SAP database or databases on the same server).


The following code should solve your problem:

Form frm = Form.CreateNewForm("myForm", SwissAddonFramework.Utils.UniqueStringGenerator.Next());

DataTable dt = DataTable.CreateNew("orders");
frm.AddDataTable(dt);

Grid orderGrid = Grid.CreateNew("orderGrid");
orderGrid.Left = 0;
orderGrid.Top = 0;
orderGrid.Width = 300;
orderGrid.Height = 300;
frm.AddItem(orderGrid);

frm.Load(); // Loads the form to sap and creates all items

dt.Columns.Add("DebtorId", DataColumn.DataColumnTypes.AlphaNumeric, 50);
dt.Columns.Add("Type", DataColumn.DataColumnTypes.AlphaNumeric, 50);
dt.Columns.Add("No", DataColumn.DataColumnTypes.AlphaNumeric, 50);
dt.Columns.Add("Price", DataColumn.DataColumnTypes.AlphaNumeric, 50);
orderGrid.DataTable = dt;

dt.Rows.Add(); // Adds a new row to the datatable and grid. Use this to fill in the data.
0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post