DataGridView

Wisej.Web.DataGridView

Namespace: Wisej.Web

Assembly: Wisej.Framework (3.5.0.0)

Represents a data grid control.

public class DataGridView : Control, ISupportInitialize, IWisejDataStore, IWisejHandler, IReadOnly

Constructors

Initializes a new instance of the DataGridView class.

Initializes a new instance of the DataGridView class with a specified data source and an event handler for the CellClick event.

NameTypeDescription

dataSource

The data source to be displayed in the DataGridView.

onCellClick

An Action delegate to handle the CellClick event. Can be null.

Initializes a new instance of the DataGridView class with a specified location and size.

NameTypeDescription

location

The location of the DataGridView on its parent control.

size

The size of the DataGridView.

Properties

Boolean: Returns or sets whether the DataGridView can automatically sort rows in the DataSource when the data is in an IList object. (Default: True)

When the DataGridView is data-bound, sorting is delegated to the DataSource when it supports sorting (see SupportsSorting). Otherwise, if the data is in an IList object and AllowSortingDataSource is true, Wisej swaps the rows in the data source. This behavior is different than WinForms, where sorting of the data source is always delegated to the data source and is otherwise ignored. Setting AllowSortingDataSource to false reverts to the same behavior as in WinForms.

Boolean: Returns or sets whether the user can add new rows. (Default: False)

Boolean: Returns or sets whether the user is allowed to delete rows from the DataGridView. (Default: False)

Boolean: Returns or sets whether manual column repositioning is enabled. (Default: False)

Boolean: Returns or sets whether users can resize columns. (Default: True)

Boolean: Returns or sets whether users can resize rows. (Default: True)

Boolean: Returns or sets whether columns are created automatically when the DataSource or DataMember properties are set. (Default: True)

You can change the default value across the application using the AutoGenerateColumnsDefault property or related AppContext switch.

Boolean: EXPERIMENTAL: Default value for the AutoGenerateColumns property. Since 3.5.6 (Default: True)

The default is true. You can set the value by code or using AppContext switches: AppContext.SetSwitch("DataGridViewAutoGenerateColumns", false);

Boolean: EXPERIMENTAL: Returns or sets whether the first row or cell, depending on SelectionMode, is automatically selected when the grid is populated. Since 3.5.6 (Default: True)

You can change the default value across the application using the AutoSelectFirstRowDefault property or related AppContext switch.

Boolean: EXPERIMENTAL: Default value for the AutoSelectFirstRow property. Since 3.5.6 (Default: True)

The default is true. You can set the value by code or using AppContext switches: AppContext.SetSwitch("DataGridViewAutoSelectFirstRow", false);

Boolean: Returns or sets a value that indicates whether the control resizes based on its contents. (Default: False)

DataGridViewAutoSizeColumnsMode: Returns or sets a value indicating how column widths are determined. (Default: None)

DataGridViewAutoSizeRowsMode: Returns or sets a value indicating how row heights are determined. (Default: None)

Throws:

Int32: Number of rows stored in a cache block. Determines the number of rows requested by the client when scrolling the grid.

It's better not to touch this value unless you know what you are doing.

BorderStyle: Returns or sets the border style for the DataGridView. (Default: Solid)

DataGridViewCellBorderStyle: Returns or sets the cell border style for the DataGridView control. (Default: Both)

DataGridViewClipboardCopyMode: Returns or sets a value that indicates whether users can copy cell text values to the Clipboard and whether row and column header text is included. (Default: EnableWithAutoHeaderText)

Int32: Returns or sets the number of columns displayed in the DataGridView. (Default: 0)

Throws:

DataGridViewCellBorderStyle: Returns or sets the border style for the column headers in the DataGridView control. (Default: Both)

DataGridViewCellStyle: Returns or sets the default column header style.

Int32: Returns or sets the height, in pixels, of the column headers row.

Throws:

  • ArgumentOutOfRangeException The specified value when setting this property is less than the minimum height of 4 pixels or is greater than the maximum height of 32768 pixels.

DataGridViewColumnHeadersHeightSizeMode: Returns or sets 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. Since 3.0.13 (Default: DisableResizing)

Boolean: Returns or sets whether the column header row is displayed. (Default: True)

Throws:

DataGridViewColumnCollection: Returns a collection that contains all the columns in the control.

DataGridViewCell: Returns or sets the currently active cell.

Throws:

  • InvalidOperationException The value of this property cannot be set because changes to the current cell cannot be committed or canceled. Or the specified cell when setting this property is in a hidden row or column. Re-entrant calling is only allowed when the DataGridView is bound to a DataSource. Re-entrant calling results from a change to the underlying data.

  • ArgumentException The specified cell when setting this property is not in the DataGridView.

Point: Returns the row and column indexes of the currently active cell.

DataGridViewRow: Returns the row containing the current cell.

String: Returns or sets the name of the list or table in the data source for which the DataGridView is displaying data. (Default: "")

Throws:

Object: Returns or sets the data source that the DataGridView is displaying data for. (Default: null)

Throws:

DataGridViewCellStyle: Returns or sets the default cell style to be applied to the cells in the DataGridView if no other cell style properties are set.

Int32: Returns or sets the default row height.

DataGridViewColumnsSortMode: Returns or sets the default SortMode for all columns when the property SortMode is set to NotSet (default). (Default: Automatic)

Control: Returns the control hosted by the current cell, if a cell with an editing control is in edit mode.

DataGridViewEditMode: Returns or sets a value indicating how to begin editing a cell. (Default: EditOnKeystrokeOrF2)

Throws:

  • Exception The specified value when setting this property would cause the control to enter edit mode, but initialization of the editing cell value failed and either there is no handler for the DataError event or the handler has set the ThrowException property to true. The exception object can typically be cast to type FormatException.

DataGridViewCell: Returns the first cell currently displayed in the DataGridView in the upper left corner.

Int32: Returns the index of the column that is the first non-frozen column displayed on the DataGridView.

Throws:

  • ArgumentOutOfRangeException The specified value when setting this property is less than 0 or greater than the number of columns in the control minus 1.

  • InvalidOperationException The specified value when setting this property indicates a column with a Visible property value of false. Or the specified value when setting this property indicates a column with a Frozen property value of true.

Int32: Returns the index of the row that is the first row displayed on the DataGridView.

Throws:

  • ArgumentOutOfRangeException The specified value when setting this property is less than 0 or greater than the number of rows in the control minus 1.

  • InvalidOperationException The specified value when setting this property indicates a row with a Visible property value of false. Or the specified value when setting this property indicates a column with a Frozen property value of true.

Int32: Returns the number of pixels by which the control is scrolled horizontally.

Boolean: Returns whether the horizontal scroll bar is visible.

Int32: Returns or sets the distance in pixels to indent each child row node level. (Default: -1)

Throws:

Boolean: Returns a value indicating whether the current cell has uncommitted changes.

Boolean: Returns a value indicating whether the currently active cell is being edited.

Boolean: Returns a value indicating whether the current row has uncommitted changes.

DataGridViewCell: Returns or set the cell located in the specified column and at the specified row.

Throws:

  • ArgumentOutOfRangeException columnIndex is less than 0 or greater than the number of columns in the control minus 1; or rowIndex is less than 0 or greater than the number of rows in the control minus 1.

DataGridViewCell: Returns or set the cell located in the specified column and at the specified row.

DataGridViewCell: Returns or set the cell located in the specified column and at the specified row.

DataGridViewCell: Returns or set the cell located in the specified location.

Boolean: Returns or sets whether the rows are always of the same height. (Default: False)

Boolean: Returns or sets whether the column and row resizing should be live: updated as the user resizes the row or the column. (Default: False)

Int32: Maximum number of blocks kept in the client cache.

It's better not to touch this value unless you know what you are doing.

Boolean: Returns or sets whether the user is allowed to select more than one cell, row, or column of the DataGridView at a time. (Default: True)

Int32: Returns the index of the row for new records.

String: Returns or sets an HTML string that is displayed when the DataGridView doesn't contain any row. (Default: "")

Boolean: Returns or sets whether the user can edit the cells of the DataGridView control. (Default: False)

Throws:

  • InvalidOperationException The specified value when setting this property is true, the current cell is in edit mode, and the current cell contains changes that cannot be committed.

  • Exception The specified value when setting this property would cause the control to enter edit mode, but initialization of the editing cell value failed and either there is no handler for the DataError event or the handler has set the ThrowException property to true. The exception object can typically be cast to type FormatException.

Boolean: Returns or sets whether the row under the pointer gets selected on a right click. (Default: False)

When the right click lands outside of a selected area the selection is not changed regardless of the value of RightClickSelection.

Int32: Returns or sets the number of rows displayed in the DataGridView. (Default: 0)

Throws:

DataGridViewColumn: Returns the DataGridViewColumn for the row headers.

Use this DataGridViewColumn to set the style and other properties for all the row headers.

DataGridViewCellStyle: Returns or sets the default style applied to the row header cells.

Int32: Returns or sets the minimum width, in pixels, of the column that contains the row headers.

Throws:

Int32: Returns or sets the minimum width, in pixels, of the column that contains the row headers.

Throws:

Boolean: Returns or sets whether the column that contains row headers is displayed. (Default: True)

Int32: Returns or sets the width, in pixels, of the column that contains the row headers.

Throws:

DataGridViewRowHeadersWidthSizeMode: Returns or sets whether the width of the row headers is adjustable and whether it can be adjusted by the user or is automatically adjusted to fit the contents of the headers. (Default: EnableResizing)

DataGridViewRowCollection: Returns a collection that contains all the rows in the DataGridView control.

DataGridViewRow: Returns or sets the row that represents the template for all the rows in the control.

Throws:

ScrollBars: Returns or sets the type of scroll bars to display for the DataGridView control. (Default: Both)

DataGridViewSelectedCellCollection: Returns the collection of selected cells.

DataGridViewSelectedColumnCollection: Returns the collection of selected columns.

DataGridViewSelectedRowCollection: Returns the collection of selected rows.

Int32: Milliseconds to wait before sending selection events to the server. (Default: 150)

Use this property to avoid flooding the server with selection change events when users quickly select rows in a data-bound DataGridView that triggers other data-bounds controls to get updated. Throws:

DataGridViewSelectionMode: Returns or sets a value indicating how the cells of the DataGridView can be selected. (Default: FullRowSelect)

Boolean: Returns or sets whether cells will display an error glyphs for each cell that contains a data entry error. (Default: True)

Boolean: Returns or sets whether or not ToolTips will show when the mouse pointer pauses on a cell. (Default: True)

Boolean: Returns or sets whether the column visibility menu button is visible. (Default: True)

Boolean: Returns or sets a value indicating whether the DataGridView widget highlights the currently focused cell. (Default: True)

Boolean: Returns or sets whether row headers will display an error glyphs for each row that contains a data entry error. (Default: True)

DataGridViewColumn: Returns the column by which the DataGridView contents are currently sorted.

Boolean: Returns or sets whether frozen rows should be sorted when sorting a column. (Default: True)

SortOrder: Returns a value indicating whether the items in the DataGridView control are sorted in ascending or descending order, or are not sorted.

DataGridViewSortSelectionMode: Returns or sets a value indicating how the DataGridView updates the selection of rows and cells when it's sorted. (Default: UpdatePosition)

The selection is always cleared when sorting a data-bound DataGridView or when the grid contains hierarchical rows.

Boolean: EXPERIMENTAL: Returns or sets whether the RETURN (Enter) key moves the focus to the cell below the current cell, rather than entering edit mode. (Default: False)

WinForms standard behavior corresponds to StandardReturn set to true.

Boolean: Returns or sets whether the TAB key moves the focus to the next control in the tab order rather than moving focus to the next cell. (Default: False)

ComponentToolCollection: Returns the instance of ComponentToolCollection associated with this control.

Position: Returns or sets the position of the ComponentTool items associated with this control. (Default: Top)

DataGridViewColumnHeaderCell: Returns or sets the header cell located in the upper left corner of the DataGridView control.

DataGridViewColumn: Returns or sets the column that displays the node open/close tree icons.

By default the DataGridView shows the open/close tree icons on the first visible and non-frozen column.

Boolean: Returns or sets whether you have provided your own data-management operations for the DataGridView control. (Default: False)

Int32: Returns the total number of visible rows currently displayed.

Boolean: Returns whether the vertical scroll bar is visible.

Methods

Creates or updates a DataGridViewSummaryRow for each group limited by the values in column groupCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

groupCol

Name of the column that determines the group break values.

summaryCol

name of the column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in column groupCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

summaryPosition

Indicates the position of the DataGridViewSummaryRow.

groupCol

Name of the column that determines the group break values.

summaryCol

Name of the column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in the columns from groupFromCol to groupToCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

groupFromCol

Name of the first column that determines the group break values.

groupToCol

Name of the last column that determines the group break values.

summaryCol

Name of the column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in the columns from groupFromCol to groupToCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

summaryPosition

Indicates the position of the DataGridViewSummaryRow.

groupFromCol

Name of the first column that determines the group break values.

groupToCol

Name of the last column that determines the group break values.

summaryCol

Name of the column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in columns groupCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

groupCol

Column that determines the group break values.

summaryCol

Column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in columns groupCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

summaryPosition

Indicates the position of the DataGridViewSummaryRow.

groupCol

Column that determines the group break values.

summaryCol

Column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in the columns from groupFromCol to groupToCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

groupFromCol

First column that determines the group break values.

groupToCol

Last column that determines the group break values.

summaryCol

Column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Creates or updates a DataGridViewSummaryRow for each group limited by the values in the columns from groupFromCol to groupToCol .

ParameterTypeDescription

summaryType

Determines the aggregation type.

summaryPosition

Indicates the position of the DataGridViewSummaryRow.

groupFromCol

First column that determines the group break values.

groupToCol

Last column that determines the group break values.

summaryCol

Column to aggregate.

Optional DataGridViewCellStyle for the summary rows.

Optional custom summary function, used when summaryType is Custom.

Returns: DataGridViewSummaryRow[]. Array of the DataGridViewSummaryRow rows displaying the aggregated values.

Populates the DataGridView from the data appending the rows to the existing rows.

ParameterTypeDescription

data

The object that contains data for the DataGridView to display.

The name of the table or list in the data object for which the DataGridView should load the data.

Returns: Int32. Numbers of rows appended.

Use this method to fill a DataGridView without binding it to the data source.

Returns whether all the cells are currently selected.

ParameterTypeDescription

includeInvisibleCells

true to include the rows and columns with the Visible property set to false.

Returns: Boolean. true if all cells (or all visible cells) are selected or if there are no cells (or no visible cells); otherwise, returns false.

Adjusts the width of the column to fit the contents of its cells including the header cell.

ParameterTypeDescription

columnIndex

The index of the column to resize; -1 indicates all columns.

Throws:

Adjusts the width of the column to fit the contents of its cells including the header cell.

ParameterTypeDescription

columnIndex

The index of the column to resize; -1 indicates all columns.

extraSpace

Additional space in pixels.

Throws:

Adjusts the width of the specified column using the specified size mode.

ParameterTypeDescription

columnIndex

The index of the column to resize; -1 indicates all columns.

autoSizeMode

Throws:

Adjusts the width of the specified column using the specified size mode.

ParameterTypeDescription

columnIndex

The index of the column to resize; -1 indicates all columns.

autoSizeMode

extraSpace

Additional space in pixels.

Throws:

Adjusts the height of the column headers to fit the contents of the largest header.

Adjusts the height of the column headers based on the contents of the header in the specified column.

ParameterTypeDescription

columnIndex

The index of the column to resize; -1 indicates all columns.

Throws:

Adjusts the width of all columns to fit the contents of their cells including the header cells.

Adjusts the width of all columns to fit the contents of their cells including the header cells.

ParameterTypeDescription

extraSpace

Additional space in pixels.

Adjusts the width of all columns using the specified size mode.

ParameterTypeDescription

autoSizeMode

Throws:

Adjusts the width of all columns using the specified size mode.

ParameterTypeDescription

autoSizeMode

extraSpace

Additional space in pixels.

Throws:

Adjusts the height of the row to fit the contents of all its cells including the header cell.

ParameterTypeDescription

rowIndex

The index of the row to resize.

Throws:

Adjusts the height of the row to fit the contents of all its cells including the header cell.

ParameterTypeDescription

rowIndex

The index of the row to resize.

extraSpace

Additional space in pixels.

Throws:

Adjusts the height of the row using the specified size mode.

ParameterTypeDescription

rowIndex

The index of the row to resize.

autoSizeMode

One of the DataGridViewAutoSizeRowMode values.

Throws:

Adjusts the height of the row using the specified size mode.

ParameterTypeDescription

rowIndex

The index of the row to resize.

autoSizeMode

One of the DataGridViewAutoSizeRowMode values.

extraSpace

Additional space in pixels.

Throws:

Adjusts the width of the row headers using the specified size mode.

ParameterTypeDescription

autoSizeMode

Throws:

Adjusts the width of the row headers using the specified size mode.

ParameterTypeDescription

autoSizeMode

extraSpace

Additional space in pixels.

Throws:

Adjusts the width of the row headers based on the contents of the header in the specified row and using the specified size mode.

ParameterTypeDescription

rowIndex

The index of the row header with the changed content.

autoSizeMode

Throws:

Adjusts the width of the row headers based on the contents of the header in the specified row and using the specified size mode.

ParameterTypeDescription

rowIndex

The index of the row header with the changed content.

autoSizeMode

extraSpace

Additional space in pixels.

Throws:

Adjusts the heights of all rows in the client's data cache to fit the contents of all their cells, including the header cells.

Adjusts the heights of all rows in the client's data cache to fit the contents of all their cells, including the header cells.

ParameterTypeDescription

extraSpace

Additional space in pixels.

Adjusts the heights of the rows using the specified size mode.

ParameterTypeDescription

autoSizeMode

One of the DataGridViewAutoSizeRowMode values.

Throws:

Puts the current cell in edit mode.

ParameterTypeDescription

true to select all the cell's contents; false to not select any contents.

Returns: Boolean. true if the current cell is already in edit mode or successfully enters edit mode; otherwise, false.

Throws:

Prevents the control from updating until the EndUpdate method is called.

Cancels edit mode for the currently selected cell and discards any changes.

Returns: Boolean. true if the cancel was successful; otherwise, false.

Returns whether the specified column can be sorted automatically.

ParameterTypeDescription

sortColumn

Column being sorted.

Returns: Boolean. true if the DataGridView should sort the data.

Clears the current selection.

Commits changes to cell without ending edit mode.

Returns: Boolean. true if the changes were committed; otherwise false.

Throws:

  • Exception The cell value could not be committed and either there is no handler for the DataError event or the handler has set the ThrowException property to true.

Invoked by all the AddSummaryRows methods to create a new DataGridViewSummaryRow in relation to the specified group .

ParameterTypeDescription

group

An array of the DataGridViewRow summarized by the group row being created.

summaryPosition

The SummaryRowPosition indicated by the AddSummaryRows method call.

groupFromCol

The first DataGridViewColumn delimiting the group.

groupToCol

The last DataGridViewColumn delimiting the group.

style

A DataGridViewCellStyle for the summary row; can be null.

Returns: