DataGridView Class

The DataGridView control provides a table for displaying data that allows for customization of cells, rows, columns, borders, and their appearance.

After you add a DataGridView control to form, you can create columns and rows that contain data and add them directly to the DataGridView using the Rows and Columns properties. You can also use the Rows collection to access DataGridViewRow objects and the DataGridViewRow.Cells property to read or write cell values directly.

After you add a DataGridView to a form (for example, DataGridView1), you add 2 columns as follows:

using elsystem.windows.forms;


method void AddColumn()

var: DataGridViewColumn col, // object variable used for a column

DataGridViewNumericUpDownColumn nudcol; // object variable used for an num up down column

begin

col = DataGridViewColumn.Create("Col 1"); // instantiate standard column titled "Col 1"

col.SortMode = DataGridViewColumnSortMode.Automatic; // set to sort based on the cell values

DataGridView1.Columns.Add(col); // add standard column to the control

nudcol = DataGridViewNumericUpDownColumn.Create("Numbers");// instantiate up-down number column titled "Numbers"

nudcol.SortMode = DataGridViewColumnSortMode.Automatic; // set to sort based on the cell values

DataGridView1.Columns.Add(nudcol); // add num up down column to the control

end;

For more about creating other column types and using DataGridView properties/events, load the Example below into TradeStation.

Namespace: elsystem.windows.forms

Properties

  Additional properties, methods, and events are described in the classes listed under Inheritance Hierarchy (see below).

  Name Type Description
Public property AllowUserToAddRows bool True if the user is allowed to add grid rows.
Public property AllowUserToDeleteRows bool True if user is allowed to delete grid rows.
Public property AllowUserToOrderColumns bool True if user is allowed to re-order columns in the grid.
Public property AllowUserToResizeRows bool True if user is allowed to resize grid rows.
Public property AlternatingRowsDefaultCellStyle object Gets the DataGridViewCellStyle object for alternating rows.
Public property BorderStyle enum Gets or sets the border style for the grid. See BorderStyle for available values.
Public property CellBorderStyle object Gets the cell border style for the grid. See DataGridViewCellBorderStyle for available values.
Public property ColumnCount int Gets or sets the number of columns displayed in the DataGridView.
Public property ColumnHeadersBorderStyle enum Gets the border style applied to the column headers. See DataGridViewCellBorderStyle for available values.
Public property ColumnHeaderDefaultCellStyle object Gets the default DataGridViewCellStyle for column headers.
Public property ColumnHeadersFont object Gets or sets the font of the text displayed by the column headers.
Public property ColumnHeadersHeight int Gets or sets the height, in pixels, of the column headers row.
Public property ColumnHeadersHeightSizeMode enum Gets or sets a value indicating whether the height of the column headers is adjustable and whether it can be adjusted by the user or is automatically adjusted to fit the contents of the headers. See DataGridViewColumnHeadersHeightSizeMode for available values.
Public property ColumnHeadersVisible bool True if the column header row is visible.
Public property Columns object Gets a collection that contains all the columns in the control. See DataGridViewColumnCollection Class.
Public property DefaultCellStyle object Gets or sets the default cell style to be applied to the cells in the DataGridView if no other cell style properties are set.
Public property EnableHeadersVisualStyles bool True if visual styles are enabled for the headers.
Public property FirstDisplayedScrollingColumnIndex int Gets or sets the index of the column that is the first column displayed in the DataGridView.
Public property FirstDisplayedScrollingRowIndex int Gets or sets the index of the row that is the first row displayed in the DataGridView.
Public property GradientMode enum Gets or sets the gradient mode. See LinearGradientMode for available values.
Public property GridColor object Gets or sets the color of the grid lines separating the cells of the grid.
Public property MultiSelect bool True if the user is allowed to select more than one cell, row, or column of the grid at a time.
Public property ReadOnly bool True if the user is not allowed to edit the cells of the grid.
Public property RowHeadersBorderStyle enum Gets or sets the border style of the row header cells. See DataGridViewHeaderBorderStyle for available values.
Public property RowHeadersDefaultCellStyle object Gets the default DataGridViewCellStyle for row headers.
Public property RowHeadersFont object Gets or sets the font of the text displayed by the row headers.
Public property RowHeadersVisible bool True if row headers are visible.
Public property RowHeadersWidth int Gets or sets the width, in pixels, of the column that contains the row headers.
Public property RowTemplate object Gets the template for DataGridViewRow objects that are created.
Public property Rows object Gets a collection that contains all the rows in the DataGridView control. See DataGridViewRowCollection.
Public property RowsDefaultCellStyle object Gets the default DataGridViewCellStyle of the rows in the DataGridView.
Public property SelectedCells object Gets the collection of cells selected by the user.
Public property SelectedColumns object Gets the collection of columns selected by the user.
Public property SelectedRows object Gets the collection of rows selected by the user.
Public property SelectionMode enum Gets or sets a value indicating how the cells can be selected. See DataGridViewSelectionMode for available values.
Public property ShowCellToolTips bool Gets or sets a Boolean value that determines whether the tooltips associated with DataGridView cells are shown.
Public property SortOrder enum Gets a value indicating whether the items in the grid are sorted in ascending or descending order, or are not sorted.
Public property SortedColumn object Gets the column object by which the DataGridView contents are currently sorted.
Methods
  Name Description
Public property ClearSelection Clears the current selection by unselecting all selected cells.
Public property Create Initializes a new instance of the class.
Public property Create(width,height) Initializes a new instance of the class. Parameters include integer values for the width and height of the control.
Public property DisplayedColumnCount( IncludePartialColumns) Returns the number of columns displayed. Includes the number of partial columns if IncludePartialColumns is true, otherwise does not include the number of partial columns.
Public property DisplayedRowCount( IncludePartialRow) Returns the number of rows displayed. Includes the number of partial rows if IncludePartialRow is true, otherwise does not include the number of partial rows.
Public property Sort(column,direction) Sets the sort direction for a specified column DataGridView column.
Events
  Name Description
Public event CellBeginEdit Occurs when editing of the selected cell begins. See DataGridViewCellCancelEventArgs for the event's arguments.
Public event CellClick Occurs when a cell in a row is clicked. See DataGridViewCellEventArgs for the event's arguments.
Public event CellEndEdit Occurs when editing of the selected cell ends. See DataGridViewCellEventArgs for the event's arguments.
Public event CellFormating Occurs when the contents of a cell need to be formatted for display. See DataGridCellFormattingEventArgs for the event's arguments.
Public event CellMouseClick Occurs when a mouse click occurs in a cell. See DataGridViewCellMouseEventArgs for the event's arguments.
Public event CellMouseDoubleClick Occurs when a mouse double-click occurs in a cell. See DataGridViewCellMouseEventArgs for the event's arguments.
Public event CellParsing Occurs when a cell leaves edit mode if the cell value has been modified. See DataGridCellParsingEventArgs for the event's arguments.
Public event CellValueChanged Occurs when the value of a cell changes. See DataGridCellEventArgs for the event's arguments.
Public event ColumnHeaderMouseClick Occurs when the user clicks a column header. See DataGridCellMouseEventArgs for the event's arguments.
Public event DataError Occurs when there is an error in assigning a value to a cell. See DataGridViewDataErrorEventArgs Class for the event's arguments.
Public event EditingControlShowing Occurs when a control for editing a cell is showing. See DataGridViewEditingControlShowingEventArgs for the event's arguments.
Public event RowHeaderMouseClick Occurs when the user clicks within the boundaries of a row header. See DataGridCellMouseEventArgs for the event's arguments.
Public event SelectionChanged Occurs when the current selection changes.
Public event SortCompare Occurs when the DataGridView compares two cell values to perform a sort operation. See DataGridSortCompareEventArgs for the event's arguments.
Example - DataGridView Column Sampler

The following TradingApp example provides a DataGridView control that includes a variety of column types that allow show you how they work and can be used as a model to create even more powerful applications of your own design.  

Import Example

DataGridViewSample       TradingApp

  1. Click on the Import Example link to import the example into TradeStation.   
  2. Go to the TradeStation platform.  From the TradingApps tab, select and run !ex_DataGridViewSample to open the sample TradingApp.
  3. To review or modify the example code, go to the TS Development Environment and open TradingApp !ex_DataGridViewSample in the EasyLanguage Editor.