The problem: there does not appear to be any way to programmatically add data to a grid; and if there actually is, I have yet to find it. So it seems, that grids must always be bound to a data source. The way around this so-called “limitation”, is to utilize a Temporary Table. A Temporary Table would be used because, unlike standard tables, it does not map to the a relational database, and will only contain data when an active record buffer is attached to it. Temporary record buffers are isolated to the user, thus if two different users are accessing the Temporary Table, they are actually pointed to different datasets. Therefore, if User (A) and User (B) are using the same form at the same time, there would not be a conflict in data integrity.
In my required modification, a form was needed to allow a user to choose from a list of customers, giving them the ability to add their selections to a grid. Once the user verified that the gird contained all of the customers they required, they could then process this list with a click of the mouse. For this particular tutorial, I will explain the basic method that I have discovered to accomplishing this task of “programmatically inserting data into a grid”.
Let’s say we want a Grid to hold a selected list of Customer Names & Numbers. What we would want to do, is create a Table in the AOT, and mark it as Temporary, containing two string fields; Name, CustNumber. We would then want to set the Data Source of our Grid to this Table, and then make a few X++ modifications
Do the following in the AOT:
1. Create a new Table, and name it TempCustList
2. Add two string fields: CustNumber, and Name
3. Right-Click the Table, and select Properties
4. Set the Temporary property to “Yes”
5. Create a new Form, and name it FrmCustList
6. Drag-and-Drop the TempCustList Table into the Form’s Data Sources
7. Expand down to the Form’s Design node.
8. Right-Click the Design node and select: New Control > Grid
9. Right-Click the Grid, and select Properties
10. Set the Name property to “GridCustList”
11. Set the Data Source property to “TempCustList”
12. Perform the following:
In the FrmCustList Form where we will be using the Temporary Table, we will want to declare the record buffer so that we can access the data in the temporary table anywhere in the form without losing it (as long as our Form remains open). For example, If you declare the Temporary Table within a mouse click method on a form’s button for example, and insert data into the Temporary Table, the data will be lost, as soon as the method completes.
public class FormRun extends ObjectRun13. On the Form, add a Button and override it’s click() method with the following code:
void clicked()The above code, will obviously add the same line to the Grid every time it is clicked, however the scope of this tutorial was simply to show you how to add data to a grid “programmatically”. A simple modification to the code would allow you to utilize the example for your needs.
// Test data, replace with a query to pull actual customer info, based on selection…
temp.Name = "Joe Smith";
temp.CustNumber = "CUST-0001";
// Insert into the Temp table
// Refresh the Data Source, which then refreshes the Grid…