Database Manual · Chapter 7

Screen Bindings

The sample's screens fall into two parts.

ScreenRoleKey bindings
ViewRunMain — DataGrid + 6 buttons + status displayData::DispData (row array) · Data::SelectIndex (selected index) · Data::DbStatusText
ModifyDlgRecord-edit dialog8 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.

xscript
// 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.

PropertyValueMeaning
DataNameData::DispDataRow array the DataGrid displays
SelectIndexDataNameData::SelectIndexWhen the user selects a row, its number (from 0) is written to this int variable; -1 when nothing is selected
IsReadOnlytrueRows 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.

xscript
"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).

OrderTitleWidthType
1id80Text
2order_no140Text
3menu_name160Text
4start_time180Text
5end_time180Text
6weight_g120RealNumber
7result100Text
8is_error100Text

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.

xscript
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.

xscript
// 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)DataNameDataTypeReadOnly
IDData::EditIdInteger✓
Order NoData::EditOrderNoString
Menu NameData::EditMenuNameString
Start TimeData::EditStartTimeString✓
End TimeData::EditEndTimeString
Weight (g)Data::EditWeightGDouble
ResultData::EditResultString
Is Error (0/1)Data::EditIsErrorInteger

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.

xscript
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.

  1. DB → Edit fields copy (before showing the dialog)
  2. GUI.ShowDialog — true (OK) / false (Cancel)
  3. 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.

ButtonActionDialogResultEffect
OKCloseDialogtrueCloses the dialog; ShowDialog returns true
CancelCloseDialogfalseCloses 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.

xscript
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"

VariableControl propertyEffect
DispData (array)DataGrid.DataNameDataGrid rows
SelectIndex (int)DataGrid.SelectIndexDataNameSelected row 0..N-1 / -1
Edit* (8)ModifyDlg TextBox.DataNameTwo-way with the dialog's input boxes
DbStatusText (string)DataLabel.DataNameStatus 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.

Subscribe