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 | |
AllowUserToAddRows | bool | True if the user is allowed to add grid rows. | |
AllowUserToDeleteRows | bool | True if user is allowed to delete grid rows. | |
AllowUserToOrderColumns | bool | True if user is allowed to re-order columns in the grid. | |
AllowUserToResizeRows | bool | True if user is allowed to resize grid rows. | |
AlternatingRowsDefaultCellStyle | object | Gets the DataGridViewCellStyle object for alternating rows. | |
BorderStyle | enum | Gets or sets the border style for the grid. See BorderStyle for available values. | |
CellBorderStyle | object | Gets the cell border style for the grid. See DataGridViewCellBorderStyle for available values. | |
ColumnCount | int | Gets or sets the number of columns displayed in the DataGridView. | |
ColumnHeadersBorderStyle | enum | Gets the border style applied to the column headers. See DataGridViewCellBorderStyle for available values. | |
ColumnHeaderDefaultCellStyle | object | Gets the default DataGridViewCellStyle for column headers. | |
ColumnHeadersFont | object | Gets or sets the font of the text displayed by the column headers. | |
ColumnHeadersHeight | int | Gets or sets the height, in pixels, of the column headers row. | |
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. | |
ColumnHeadersVisible | bool | True if the column header row is visible. | |
Columns | object | Gets a collection that contains all the columns in the control. See DataGridViewColumnCollection Class. | |
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. | |
EnableHeadersVisualStyles | bool | True if visual styles are enabled for the headers. | |
FirstDisplayedScrollingColumnIndex | int | Gets or sets the index of the column that is the first column displayed in the DataGridView. | |
FirstDisplayedScrollingRowIndex | int | Gets or sets the index of the row that is the first row displayed in the DataGridView. | |
GradientMode | enum | Gets or sets the gradient mode. See LinearGradientMode for available values. | |
GridColor | object | Gets or sets the color of the grid lines separating the cells of the grid. | |
MultiSelect | bool | True if the user is allowed to select more than one cell, row, or column of the grid at a time. | |
ReadOnly | bool | True if the user is not allowed to edit the cells of the grid. | |
RowHeadersBorderStyle | enum | Gets or sets the border style of the row header cells. See DataGridViewHeaderBorderStyle for available values. | |
RowHeadersDefaultCellStyle | object | Gets the default DataGridViewCellStyle for row headers. | |
RowHeadersFont | object | Gets or sets the font of the text displayed by the row headers. | |
RowHeadersVisible | bool | True if row headers are visible. | |
RowHeadersWidth | int | Gets or sets the width, in pixels, of the column that contains the row headers. | |
RowTemplate | object | Gets the template for DataGridViewRow objects that are created. | |
Rows | object | Gets a collection that contains all the rows in the DataGridView control. See DataGridViewRowCollection. | |
RowsDefaultCellStyle | object | Gets the default DataGridViewCellStyle of the rows in the DataGridView. | |
SelectedCells | object | Gets the collection of cells selected by the user. | |
SelectedColumns | object | Gets the collection of columns selected by the user. | |
SelectedRows | object | Gets the collection of rows selected by the user. | |
SelectionMode | enum | Gets or sets a value indicating how the cells can be selected. See DataGridViewSelectionMode for available values. | |
ShowCellToolTips | bool | Gets or sets a Boolean value that determines whether the tooltips associated with DataGridView cells are shown. | |
SortOrder | enum | Gets a value indicating whether the items in the grid are sorted in ascending or descending order, or are not sorted. | |
SortedColumn | object | Gets the column object by which the DataGridView contents are currently sorted. |
Methods
Name | Description | |
ClearSelection | Clears the current selection by unselecting all selected cells. | |
Create | Initializes a new instance of the class. | |
Create(width,height) | Initializes a new instance of the class. Parameters include integer values for the width and height of the control. | |
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. | |
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. | |
Sort(column,direction) | Sets the sort direction for a specified column DataGridView column. |
Events
Name | Description | |
CellBeginEdit | Occurs when editing of the selected cell begins. See DataGridViewCellCancelEventArgs for the event's arguments. | |
CellClick | Occurs when a cell in a row is clicked. See DataGridViewCellEventArgs for the event's arguments. | |
CellEndEdit | Occurs when editing of the selected cell ends. See DataGridViewCellEventArgs for the event's arguments. | |
CellFormating | Occurs when the contents of a cell need to be formatted for display. See DataGridCellFormattingEventArgs for the event's arguments. | |
CellMouseClick | Occurs when a mouse click occurs in a cell. See DataGridViewCellMouseEventArgs for the event's arguments. | |
CellMouseDoubleClick | Occurs when a mouse double-click occurs in a cell. See DataGridViewCellMouseEventArgs for the event's arguments. | |
CellParsing | Occurs when a cell leaves edit mode if the cell value has been modified. See DataGridCellParsingEventArgs for the event's arguments. | |
CellValueChanged | Occurs when the value of a cell changes. See DataGridCellEventArgs for the event's arguments. | |
ColumnHeaderMouseClick | Occurs when the user clicks a column header. See DataGridCellMouseEventArgs for the event's arguments. | |
DataError | Occurs when there is an error in assigning a value to a cell. See DataGridViewDataErrorEventArgs Class for the event's arguments. | |
EditingControlShowing | Occurs when a control for editing a cell is showing. See DataGridViewEditingControlShowingEventArgs for the event's arguments. | |
RowHeaderMouseClick | Occurs when the user clicks within the boundaries of a row header. See DataGridCellMouseEventArgs for the event's arguments. | |
SelectionChanged | Occurs when the current selection changes. | |
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.
DataGridViewSample TradingApp |
- Click on the Import Example link to import the example into TradeStation.
- Go to the TradeStation platform. From the TradingApps tab, select and run !ex_DataGridViewSample to open the sample TradingApp.
- To review or modify the example code, go to the TS Development Environment and open TradingApp !ex_DataGridViewSample in the EasyLanguage Editor.
Inheritance Hierarchy
elsystem.windows.forms.ELWFComponent
elsystem.windows.forms.Control
elsystem.windows.forms.DataGridView