You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Overview

This section discusses how to configure the DataGrid component.


On this page:



Configuring a DataGrid Window

Double-click any DataGrid window object in the display to configure it. 

Data Grid window configuration

Field

Description

Control Name

Defines a name for the control so it can be accessed in the code-behind script. See Display Code Behind.

Data Source

Enter the dataset table or query to use for the window.

SelectedValues

Enter a string tag or array tag to receive the contents of the selected row.

SelectedIndex

Enter a tag to receive the number of the currently selected row. Row numbering starts with 0.

LinesCount

Select a tag to receive the number of lines in the window.

Pause

Set an object to define if the DataGrid will be updated or not when the data changes.

Theme

Select the theme for the window.

BindingMode

Select the binding mode. See BindingMode Enum by Microsoft. 

AllowInsert

Select to allow users to add rows.

Column Titles

Select to display column titles.

Transpose

Select to transpose columns to rows.

OneClick Edit

Select to edit cells on first click.

Allow Delete

Select to allow the data to be deleted from a grid

AllowSort

Select to allow users to sort the data by column.

Auto Column

  • Select to have the system automatically include all table or query columns in the window. If selected, you do not have to configure the columns below. To customize specific columns, add the column to the column list and configure the settings to the right (described below).
  • Deselect to manually configure each column that you want to include using the Columns list and settings to the right (described below).

Multiple Selection

Check to make multiple selection possible.

Edit SelectedValues

Check to make it possible to edit multiple selected values.

Show Header

Check to show headers on grid.

Filter

Enter SQL statement to limit the data displayed.

Columns

For each column you want to customize or include manually, add the column and configure the settings to the right of the list (described below).

Visible

Select to allow the column to display in the data grid window.

Editable

Select to let users edit the column.

Show in Column Chooser

Select to include the column in the column chooser, which lets users select the columns to display.

FieldName

Enter a name for the column.

Editor

Select the column data type.

Title

Enter the text for the column header.

Width

Enter the initial column width, in WPF units (device-independent pixels; one WPF = 1/96 inch).

Sort

Select how to initially sort the column.

Alignment

Select to set the horizontal alignment.

  • Left - Align the data to the left side in the column.
  • Right - Align the data to the right side in the column.
  • Center - Align the data to the center in the column.
  • Stretch - This will stretch the column horizontally.


Example of a DataGrid with 2 Decimal Places

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.



How to make the selected row be the first row in the grid


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);

Frozen Columns

The data grid also supports the feature to freeze columns. That means they stay visible while you scoll 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...

The root page @parent could not be found in space v10.

  • No labels