windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-baseview-0078e0a8.md
Gets how many data rows are contained within the View.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[Browsable(false)]
public int DataRowCount { get; }
<Browsable(False)>
Public ReadOnly Property DataRowCount As Integer
| Type | Description |
|---|---|
| Int32 |
An integer value providing a count of the number of data rows in the View.
|
Note that data rows can be hidden within collapsed groups when data grouping is applied. The DataRowCount property returns the total number of data rows regardless of whether they are within collapsed groups or not. Also, the property’s return value is not always the same as the number of records within the associated data source. When data filtering is applied, the DataRowCount property returns the number of rows that match the filter condition.
Note
Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the DataRowCount member must not be invoked for these Views. The DataRowCount member can only be used with Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.
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
The following code snippets (auto-collected from DevExpress Examples) contain references to the DataRowCount property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-grid-implement-crud-operations-xpinstantfeedbacksource/CS/DXServermode2/Form1.cs#L43
{
if (customerToEdit != null && gridView1.DataRowCount > oldRowsCount)
{
winforms-grid-multiple-row-selection-web-style-checkboxes/CS/E1271/CheckMarkSelection.cs#L63
// slow:
for(int i = 0; i < _view.DataRowCount; i++)
selection.Add(_view.GetRow(i));
winforms-grid-implement-crud-operations-linqservermodesource/CS/LinqServerModeSource/Form1.cs#L71
}
for (int i = 0; i <gridView1.DataRowCount; i++)
{
winforms-preserve-grid-state-on-refresh/CS/RefreshHelperClass.cs#L121
GridColumn column = view.Columns[keyFieldName];
for(int i = 0; i < view.DataRowCount; i++)
if(view.GetMasterRowExpanded(i))
winforms-grid-prevent-focusing-group-row/CS/Form1.cs#L46
if (focusedRowHandle < 0) focusedRowHandle = 0;
if (focusedRowHandle >= view.DataRowCount) focusedRowHandle = view.DataRowCount - 1;
}
winforms-grid-implement-crud-operations-xpinstantfeedbacksource/VB/DXServermode2/Form1.vb#L39
Private Sub gridView1_AsyncCompleted(ByVal sender As Object, ByVal e As EventArgs)
If customerToEdit IsNot Nothing AndAlso gridView1.DataRowCount > oldRowsCount Then
For i As Integer = 0 To gridView1.DataRowCount - 1
winforms-grid-multiple-row-selection-web-style-checkboxes/VB/E1271/CheckMarkSelection.vb#L84
' slow:
For i As Integer = 0 To _view.DataRowCount - 1
selection.Add(_view.GetRow(i))
winforms-grid-implement-crud-operations-linqservermodesource/VB/LinqServerModeSource/Form1.vb#L64
Next i
For i As Integer = 0 To gridView1.DataRowCount - 1
If result Is gridView1.GetRowCellValue(i, gridView1.Columns("CustomerID")).ToString() Then
winforms-preserve-grid-state-on-refresh/VB/RefreshHelperClass.vb#L130
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = 0 To view.DataRowCount - 1
If view.GetMasterRowExpanded(i) Then list.Add(view.GetRowCellValue(i, column))
winforms-grid-prevent-focusing-group-row/VB/Form1.vb#L45
If focusedRowHandle < 0 Then focusedRowHandle = 0
If focusedRowHandle >= view.DataRowCount Then focusedRowHandle = view.DataRowCount - 1
End If
See Also