Screen Bindings
The sample's screens fall into two parts.
| Screen | Role | Key bindings |
|---|---|---|
| ViewRun | Main — DataGrid + 6 buttons + status display | Data::DispData (row array) · Data::SelectIndex (selected index) · Data::DbStatusText |
| ModifyDlg | Record-edit dialog | 8 fields such as Data::EditId · EditOrderNo · EditMenuName · EditEndTime |
The script only updates data (array DispData[], double EditWeightG, etc.), and the controls draw from those values —
that wiring is the core of this chapter.
1) ViewRun · DataGrid Binding
Data.xms declares these two variables.
// Row array for the DataGrid (CSV : id,order_no,menu_name,start_time,end_time,weight_g,result,is_error)
array DispData[] = {"",};
// Currently selected row index, updated by the XDataGrid (-1 = no selection)
int SelectIndex = -1;The DataGrid control of ViewRun is set as follows in the Property Editor.
| Property | Value | Meaning |
|---|---|---|
| DataName | Data::DispData | Row array the DataGrid displays |
| SelectIndexDataName | Data::SelectIndex | When the user selects a row, its number (from 0) is written to this int variable; -1 when nothing is selected |
| IsReadOnly | true | Rows are not edited in the grid; changes go through the buttons and the dialog only |
CSV Row Format
Each element of DispData is one comma-joined line.
"42,O1042,Latte,2026-05-06 09:31:02,2026-05-06 09:31:30,300,Done,0"DB_Refresh() builds this format from the GetRowArray(i) result (Chapter 6).
Columns Definition
The DataGrid's Columns property defines 8 columns, so the N-th CSV value appears in the N-th column. The sample's settings are below (all center-aligned).
| Order | Title | Width | Type |
|---|---|---|---|
| 1 | id | 80 | Text |
| 2 | order_no | 140 | Text |
| 3 | menu_name | 160 | Text |
| 4 | start_time | 180 | Text |
| 5 | end_time | 180 | Text |
| 6 | weight_g | 120 | RealNumber |
| 7 | result | 100 | Text |
| 8 | is_error | 100 | Text |
Update Flow
The script only needs DispData.Clear() → repeated Add(). Each line of DB_Refresh() is stacked into DispData,
and the DataGrid redraws from that array.
DispData.Clear();
for( i, 0, rows-1 )
{
array row = DB["local"].GetRowArray(i);
DispData.Add($"{row[0]},{row[1]},{row[2]},{row[3]},{row[4]},{row[5]},{row[6]},{row[7]}");
}2) ModifyDlg — Dialog + Two-way Binding
ModifyDlg is a view module (ViewType Window, 540 × 540) shown modally with GUI.ShowDialog("ModifyDlg").
CloseDialogOnEscape is on, so it can be closed with Esc.
The 8 Edit Fields
Variables declared in Data.xms are bound one-to-one to the dialog's input boxes.
// Excerpt from Data.xms
int EditId = 0; // PK (read-only display)
string EditOrderNo = "";
string EditMenuName = "";
string EditStartTime = ""; // read-only display
string EditEndTime = "";
double EditWeightG = 0.0;
string EditResult = "";
int EditIsError = 0;All input boxes of the dialog are TextBox controls whose DataName points to these variables. Values the user types are written to the Data::Edit* variables automatically.
| Box (Caption) | DataName | DataType | ReadOnly |
|---|---|---|---|
| ID | Data::EditId | Integer | ✓ |
| Order No | Data::EditOrderNo | String | |
| Menu Name | Data::EditMenuName | String | |
| Start Time | Data::EditStartTime | String | ✓ |
| End Time | Data::EditEndTime | String | |
| Weight (g) | Data::EditWeightG | Double | |
| Result | Data::EditResult | String | |
| Is Error (0/1) | Data::EditIsError | Integer |
ID is used in WHERE id = ? of the UPDATE and Start Time is not updated, so both boxes are locked with ReadOnly.
Dialog Call Flow
DB_OpenModifyDlg(), called by the Modify... button, is the standard pattern.
FUNCTION DB_OpenModifyDlg()
{
// ( IsOpen · SelectIndex guards omitted )
// 1) Copy the selected row's values into the edit fields
EditId = DB["local"].GetValueInt(/*row*/SelectIndex, /*colName*/"id");
EditOrderNo = DB["local"].GetValue(/*row*/SelectIndex, /*colName*/"order_no");
EditMenuName = DB["local"].GetValue(/*row*/SelectIndex, /*colName*/"menu_name");
EditStartTime = DB["local"].GetValue(/*row*/SelectIndex, /*colName*/"start_time");
EditEndTime = DB["local"].GetValue(/*row*/SelectIndex, /*colName*/"end_time");
EditWeightG = DB["local"].GetValueDouble(/*row*/SelectIndex, /*colName*/"weight_g");
EditResult = DB["local"].GetValue(/*row*/SelectIndex, /*colName*/"result");
EditIsError = DB["local"].GetValueInt(/*row*/SelectIndex, /*colName*/"is_error");
// 2) Show the dialog - returns true (OK) / false (Cancel)
if( GUI.ShowDialog(/*viewModuleName*/"ModifyDlg") == false )
{
Log($"DB_OpenModifyDlg : cancelled by user");
return false;
}
// 3) On OK, UPDATE with the edited values
return DB_UpdateModified();
}The three steps are clearly separated.
- DB → Edit fields copy (before showing the dialog)
GUI.ShowDialog—true(OK) /false(Cancel)- Edit fields → DB UPDATE (
DB_UpdateModified— updates order_no · menu_name · end_time · weight_g · result · is_error in a transaction)
How GUI.ShowDialog Gets OK / Cancel
The two buttons in the dialog have Action CloseDialog, and their DialogResult value decides the result.
| Button | Action | DialogResult | Effect |
|---|---|---|---|
| OK | CloseDialog | true | Closes the dialog; ShowDialog returns true |
| Cancel | CloseDialog | false | Closes the dialog; ShowDialog returns false |
Closing with Esc also gives false. This simple agreement keeps the calling code short.
3) Status Label — DbStatusText
Data.xms has a single string variable.
string DbStatusText = "● CLOSED";The DataName of the DataLabel at the top of ViewRun is Data::DbStatusText, so simply setting it to "● OPEN" in DB_Open()
and "● CLOSED" in DB_Close() updates the screen.
Summary — "Update the Data and the Screen Follows"
| Variable | Control property | Effect |
|---|---|---|
DispData (array) | DataGrid.DataName | DataGrid rows |
SelectIndex (int) | DataGrid.SelectIndexDataName | Selected row 0..N-1 / -1 |
Edit* (8) | ModifyDlg TextBox.DataName | Two-way with the dialog's input boxes |
DbStatusText (string) | DataLabel.DataName | Status text |
The script only handles variables — that is QMachineStudio's data-centered way of building screens. The next chapter covers the events (button clicks · DB events) that tie these flows together.