DataGridView

DataGridView (Data Grid)

The DataGridView is an advanced control object used to display, manage, and edit data in a tabular structure within your SCADA projects.

Unlike simple controls, this object presents data in a structured format consisting of rows and columns.

Common Use Cases
  • Alarms: Displaying a list of active or historical alarms.
  • Recipes: Displaying and managing all parameters of a recipe (Step, Value, Description) as a table.
  • Historical Data (Logging): Listing historical production data, operator action logs, or error logs queried from a database.
Basic Configuration and Operation

The configuration of this object differs fundamentally from others:

1. Designing Columns (Advanced Panel)

  • First, go to the object’s Advanced panel.
  • Find the Columns property under the “Other” category. This is where you design the grid layout.
  • For each column, you define properties such as Name (code name), HeaderText (title visible to the user), Width, and ReadOnly.

2. Adding Data (Events and Scripting)

  • The rows of a DataGridView are almost never bound directly to a tag from the Properties panel.
  • Data is added to the grid during Runtime using Scripts.
  • Example: A “Refresh” button triggers a script, the script fetches data from the database, and populates the grid using the command DataGridView1.Rows.Add(…).

3. Managing Interaction (Properties Panel)

  • The Properties panel is used to track how the operator interacts with the grid after it has been populated (e.g., tracking which row is selected).

Properties Panel – Key Properties

Value

  • Index:
    • Function: This is a two-way link connecting the sequence number of the row highlighted by the operator to an internal tag. The first row is 0, the second is 1.
    • Read: If the operator selects the 3rd row, the connected tag receives the value 2.
    • Write: If the connected tag (e.g., PLC_Request_Index) is set to 4 by a script or the PLC, the grid automatically highlights the 5th row.

Events

  • Index Changed:
    • Function: Triggered the moment the operator’s selection moves to a different row in the grid.
    • Use Case: This is the most frequently used event. When an operator selects a row in a recipe list, it is used to trigger a script to show the detailed data for that specific row.

Advanced Panel – Key Properties

  • Columns (Collection)
    • The blueprint of the grid. Here, you configure properties (e.g., HeaderText – “Temperature”, Name – “colTemp”, ReadOnly – True) for each column you add.
  • AllowUserToAddRows
    • If True, an empty row appears at the bottom of the grid, allowing the operator to manually add rows.
  • AllowUserToDeleteRows
    • Allows the operator to delete rows.
  • ReadOnly (Global)
    • If True, it locks the entire grid. The operator cannot edit any cells (regardless of individual column settings).
  • SelectionMode
    • FullRowSelect: When the operator clicks a cell, the entire row belonging to that cell is selected. Ideal for row-based operations (selecting recipes, selecting alarms).
    • CellSelect: Only the single clicked cell is selected.
  • MultiSelect
    • Prevents the operator from selecting multiple rows using the Ctrl key. Generally disabled when you want the operator to focus on a single action.
  • RowHeadersVisible
    • If True, an empty header column containing the selection arrow (▶︎) appears on the far left of the grid. Setting this to False usually provides a cleaner look.
  • AlternatingRowsDefaultCellStyle (Zebra Style)
    • This is where you configure “zebra” styling (differentiating background colors for odd and even rows) to make the grid easier to read.

Common Usage Examples

Example: Production Mode Selection

The operator selects the machine’s operating mode (Speed) from a list, and the PLC automatically highlights the currently active mode in this list.

  1. Add a DataGridView to the screen.
  2. Go to Advanced -> Columns and add a single column: Name=”Mode”, HeaderText=”Operating Mode”.
  3. Add the machine modes to the rows sequentially (via script or initial setup):
  • Row 0: “ECO Mode (Slow)”
  • Row 1: “Standard Mode (Medium)”
  • Row 2: “Turbo Mode (Fast)”
  1. Set Advanced -> ReadOnly to True (Text cannot be changed, only selected).
  2. Set Advanced -> SelectionMode to FullRowSelect (Clicking selects the whole row).
  3. Select the DataGridView object and go to the Properties panel.
  4. Find the Index property under the Value category.
  5. Bind the Active_Mode_No (Int) tag from the PLC to the Tag cell next to it.

Result:

  • When the operator clicks on the “Turbo Mode” row (3rd row), the DataGridView automatically writes the index number of this row (2) to the Active_Mode_No tag. The machine switches to Turbo mode.
  • Conversely, if the PLC automatically downgrades the mode to “ECO Mode” due to a fault (setting Active_Mode_No = 0), the selection in the table on the screen automatically shifts to the first row.

Leave a Reply