windowsforms-3484-controls-and-libraries-data-grid-views-grid-view-rows.md
Data Grid row types include data rows (which display data source records) and non-data rows (group rows, new item rows, etc.).
Default row height is determined by font settings. The Data Grid exposes the following API to modify these heights.
Row cells clip content that they cannot display entirely. To change this behavior, utilize the MemoEdit, TokenEdit, or PictureEdit editors as in-place editors for required columns and enable the GridOptionsView.RowAutoHeight setting. This will allow Data Grid data rows to dynamically adapt to the content and gain different heights.
Demo: Auto Row Height
You can hide column and row borders by disabling the GridOptionsView.ShowVerticalLines and GridOptionsView.ShowHorizontalLines settings.
A row indicator panel is a horizontal strip docked to the Data Grid’s left edge. Users can click this bar to select any Data Grid row.
Row indicator panel displays various icons depending on what row is currently selected and which row operation is ongoing.
Related API
GridOptionsView.ShowIndicator — Shows/hides the row indicator panel.
GridView.IndicatorWidth — Gets or sets the panel width.
GridView.CustomDrawRowIndicator — Manually redraws the panel.
If the ColumnViewOptionsSelection.MultiSelect option is enabled, end users are able to select multiple rows using marquee selection, the keyboard arrow keys, and mouse clicks with the Ctrl/Shift keys pressed.
Related API
ColumnView.SelectRow - Adds a row (card) to the current selection.
ColumnView.GetSelectedRows - Returns handles of the selected rows (or cards).
ColumnView.DeleteSelectedRows - Deletes the selected rows/cards in multiple selection mode or focused row/card in single selection mode.
Along with clicking a row indicator panel, users can utilize check boxes to select data rows. To enable these check boxes, set the GridOptionsSelection.MultiSelectMode property to the GridMultiSelectMode.CheckBoxRowSelect value. Web style selection is available only when row multi-select is on.
Related API
GridOptionsSelection.ShowCheckBoxSelectorInColumnHeader — Enable this property to display a check box in the column header area. This feature allows users to select all Data Grid rows simultaneously.
GridOptionsSelection.ShowCheckBoxSelectorInGroupRow — Enable this property to display check boxes in group rows. This feature allows users to select all Data Grid rows that belong to a specific group.
Demo: Web Style Row Selection
Every Data Grid row has three integer values that identify it: a data source index , a row handle and a visible index.
Data source indexes
Row handles
Visible indexes
For master-detail data, all detail Views have their own unique visible indexes and row handles.
The following table lists related API:
|
API
|
Description
| | --- | --- | |
|
Returns the row handle of the currently focused row. To obtain the record displayed in the focused row, use the GetFocusedRow and GetFocusedDataRow methods.
| |
|
Allows you to obtain a row handle by a row cell value.
| |
|
Returns whether a row with the given handle is a regular data row (not a group row, auto filter row, etc.).
| |
ColumnView.GetRowHandle, ColumnView.GetDataSourceRowIndex
|
Return row handles by indexes of related records in a data source and vice versa.
| |
ColumnView.GetVisibleIndex, ColumnView.GetVisibleRowHandle
|
Return row handles by the visible indexes of rows and vice versa.
| |
ColumnView.GetRow, ColumnView.GetDataRow
|
Return an object that is the row with the given handle.
| |
GridControl.NewItemRowHandle, GridControl.AutoFilterRowHandle
|
Numeric constants that specify row handles for the new item and auto filter rows, respectively.
| |
GridControl.ColumnsRowHandle, GridControl.BandsRowHandle, GridControl.GroupPanelRowHandle
|
Numeric constants that specify row handles for rows that contain column headers, bands, and the group panel, respectively. You can only access these rows if the OptionsNavigation.AllowHeaderNavigation property is active.
| |
|
A constant that is returned when the Grid fails to obtain a particular row. For example, an invalid row handle is returned by the GridView.GroupRowCollapsing event arguments if this event fires when all Data Grid groups collapse simultaneously (for example, after calling the GridView.CollapseAllGroups method).
| |
|
Scrolls a View up or down to the row with the required visible index.
|
The GridView.RowCount property returns the number of records that are currently visible in the view. When the number changes, the BaseView.RowCountChanged event fires. For example, you can handle this event to show a form that allows a user to create a new record when no records meet the current search query.
using DevExpress.XtraGrid.Views.Grid;
private void gridView1_RowCountChanged(object sender, EventArgs e) {
GridView view = sender as GridView;
if(view.RowCount == 0) {
using(var form = new SpaceObjectForm())
form.ShowDialog();
}
}
Imports DevExpress.XtraGrid.Views.Grid
Private Sub gridView1_RowCountChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gridView1.RowCountChanged
Dim view As GridView = TryCast(sender, GridView)
If view.RowCount = 0 Then
Using form = New SpaceObjectForm()
form.ShowDialog()
End Using
End If
End Sub
When you need to process all Data Grid rows one by one, use the following technique.
The code sample below iterates through grid records and reduces the “Price” column values by 10 percent.
private void UpdatePrice(DevExpress.XtraGrid.Views.Base.ColumnView View) {
// Obtain the Price column.
DevExpress.XtraGrid.Columns.GridColumn col = View.Columns.ColumnByFieldName("Price");
if (col == null) return;
View.BeginSort();
try {
// Obtain the number of data rows.
int dataRowCount = View.DataRowCount;
// Traverse data rows and change the Price field values.
for (int i = 0; i < dataRowCount; i++) {
object cellValue = View.GetRowCellValue(i, col);
double newValue = Convert.ToDouble(cellValue) * 0.9;
View.SetRowCellValue(i, col, newValue);
}
} finally { View.EndSort(); }
}
Private Sub UpdatePrice(ByVal View As DevExpress.XtraGrid.Views.Base.ColumnView)
' Obtain the Price column.
Dim Col As DevExpress.XtraGrid.Columns.GridColumn = View.Columns.ColumnByFieldName("Price")
If Col Is Nothing Then Exit Sub
View.BeginSort()
Try
' Obtain the number of data rows.
Dim DataRowCount As Integer = View.DataRowCount
' Traverse data rows and change the Price field values.
Dim I As Integer
For I = 0 To DataRowCount - 1
Dim CellValue As Object = View.GetRowCellValue(I, Col)
Dim NewValue As Double = Convert.ToDouble(CellValue) * 0.9
View.SetRowCellValue(I, Col, NewValue)
Next
Finally
View.EndSort()
End Try
End Sub
See Also
End-User Capabilities: Resizing Cards
End-User Capabilities: Expanding and Collapsing Rows and Cards