This section discusses how to configure the DataGrid component.
On this page:
This component is Portable. It runs both on Windows (WPF) and on Web Pages hosted in any platform.
Double-click any DataGrid window object in the display to configure it.
DataGrid General Settings | |
---|---|
Field | Description |
Data Source | It defines the dataset table or query from which the data grid will get the data. |
Control Name | It defines a name for the control so it can be accessed in the code-behind script. See Display Code Behind. |
Selected Values | Captures the contents of the selected row using a string tag or array tag. |
Selected Index | Captures the number of the currently selected row, starting with 0, using a tag. |
Line Count | Receives the number of lines in the window using a selected tag. |
Pause Update | Determines whether the DataGrid updates when the data changes by setting an object. |
Grid Settings | Stores the DataGrid configuration using a retentive text tag, maintaining settings after a shutdown or restart. |
Filter | Limits the displayed data using an SQL statement. |
Binding | Sets the binding mode for the DataGrid. The options are:
|
Theme | Selects the visual style for the DataGrid. |
Allow Edit | Enables editing of the selected values. |
Allow Insert | Allows users to add rows. |
Allow Delete | Allows row deletion. |
Column Titles | Displays column titles. |
Allow Sort | Allows users to sort data. |
Transpose | Enables transposing of columns to rows. |
Auto Columns | This option automatically includes all table or query columns in the window. Select this option to have the system include all columns without manual configuration. |
OneClick Edit | Allows editing of cells on the first click. |
Multiple Selection | Enables selecting multiple rows or cells simultaneously. |
Header | Provides space for dragging column titles to group data. |
DataGrid Configuration | |
---|---|
Field | Description |
Field | Specifies the name of the column in the DataGrid. |
Title | Sets the text displayed as the header for the column. |
Width | Defines the initial width of the column. |
Sort | Determines the initial sort order for the column. The options are:
|
Visible | Shows or hides the column in the DataGrid. |
Editable | Allows or disallows editing of the column's data. |
Show in Column Chooser | Includes the column in the column chooser, allowing users to select which columns to display. |
Auto Resize | Automatically adjusts the column width based on content. |
Editor | Sets the data type of the column (e.g., text, numeric). The options are:
|
Alignment | Specifies the horizontal alignment of the column content (e.g., left, right, center). The options are:
|
Format | Defines the format for displaying the column's data (e.g., number format, date format). |
There are cases where even after setting the tag format to display in the grid and making data changes in the property window to show only 2 decimals, it does not work. In this way, the grid somehow shows more decimals than what is shown in the property window.
To resolve this situation, you can set the column where you want to limit the decimal values to numeric and in the format field put "0.00" in the DataGrid settings menu, this can make the data grid limit the number of decimal places.
TDataGridWindow grid = CurrentDisplay.GetDataGrid("Grid"); Xceed.Wpf.DataGrid.DataGridControl dg = grid.GridControl.DataGridObj; ScrollViewer myScrollViewer = (ScrollViewer)dg.Template.FindName("PART_ScrollViewer", dg); if (myScrollViewer == null || dg.Items.Count == 0) return; string columnName = "Message"; int selIndex = -1; for (int i = 0; i < dg.Items.Count; i++) { DataRowView rowView = dg.Items[i] as DataRowView; if (TK.To<string>(rowView.Row[columnName]).StartsWith(@tag.txtfind)) { dg.Items.MoveCurrentTo(rowView); dg.SelectedItem = rowView; selIndex = i; break; } } if (selIndex >= 0) myScrollViewer.ScrollToVerticalOffset(selIndex); |
The data grid also supports the feature to freeze columns. That means they stay visible while you scroll horizontally through all columns. This is a useful feature to keep a referencing column like an ID or a name always visible to keep your orientation while scrolling.
To freeze a numer of columns just set the FrozenColumnCount
property to the number of columns you want to freeze.
In the code below for CodeBehind, it enables freezing/fixing the left-most columns in a DataGridWindow element.
The 'FixedColumnCount' property tallies the number of columns (from left to right) that will be fixed. The 'ShowFixedColumnSplitter' allows you to select the columns using the mouse (by clicking and dragging).
public void DisplayOpening() { TDataGridWindow gridWindow = CurrentDisplay.GetDataGrid("grid"); gridWindow.AfterInitilizationEvent += AfterInitilization; } public void DisplayIsOpen() { // Add your code here } public void DisplayClosing() { TDataGridWindow gridWindow = CurrentDisplay.GetDataGrid("grid"); gridWindow.AfterInitilizationEvent -= AfterInitilization; } private void AfterInitilization(object sender, EventArgs e) { TDataGridWindow gridWindow = CurrentDisplay.GetDataGrid("Grid"); Xceed.Wpf.DataGrid.Views.TableView tableView = gridWindow.GridControl.DataGridObj.View as Xceed.Wpf.DataGrid.Views.TableView; tableView.FixedColumnCount = 1; tableView.ShowFixedColumnSplitter = true; } |
In this section: