Back to Devexpress

GridView.RowCount Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-917ceadf.md

latest7.3 KB
Original Source

GridView.RowCount Property

Returns the number of visible Grid records.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
public override int RowCount { get; }
vb
Public Overrides ReadOnly Property RowCount As Integer

Property Value

TypeDescription
Int32

The number of visible Grid rows.

|

Remarks

This property overrides the BaseView.RowCount property to increment its value in these cases:

Note

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the RowCount member must not be invoked for these Views. The RowCount 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 illustrates how to paste a clipboard value into all cells under the “TargetColumn” column.

csharp
private void gridView_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
    if (e.Control && e.KeyCode == System.Windows.Forms.Keys.V) {
        var text = Clipboard.GetText();
        for (int i = 0; i < gridView.RowCount; i++) {
            if (gridView.IsDataRow(i)) {
                this.gridView.SetRowCellValue(i, "TargetColumn", text);
                e.Handled = true;
            }
        }
    }
}
vb
'INSTANT VB NOTE: This code snippet uses implicit typing. You will need to set 'Option Infer On' in the VB file or set 'Option Infer' at the project level.

Private Sub gridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    If e.Control AndAlso e.KeyCode = System.Windows.Forms.Keys.V Then
        Dim text = Clipboard.GetText()
        For i As Integer = 0 To gridView.RowCount - 1
            If gridView.IsDataRow(i) Then
                Me.gridView.SetRowCellValue(i, "TargetColumn", text)
                e.Handled = True
            End If
        Next i
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the RowCount 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-gridlookupedit-multiple-item-selection/CS/Form1.cs#L100

csharp
foreach(string val in values) {
    for(int i = 0; i < view.RowCount; i++) {
        if(view.GetRowCellValue(i, fieldName).ToString() == val)

winforms-grid-select-detail-rows-when-selecting-master-row/CS/MasterDetailSelectionHelper.cs#L28

csharp
int masterRowHandle = _GridView.SourceRowHandle;
if (_GridView.GetSelectedRows().Length == _GridView.RowCount)
{

winforms-reporting-create-grid-based-report/CS/ConvertGridToReportExample/Form1.cs#L57

csharp
dTable.Columns.Add(c.FieldName, c.ColumnType);
for (int r = 0; r < gridView.RowCount; r++)
{

winforms-gridlookupedit-multiple-item-selection/VB/Form1.vb#L97

vb
For Each val As String In values
    For i As Integer = 0 To view.RowCount - 1
        If Equals(view.GetRowCellValue(i, fieldName).ToString(), val) Then selection.Add(i)

winforms-grid-select-detail-rows-when-selecting-master-row/VB/MasterDetailSelectionHelper.vb#L24

vb
Dim masterRowHandle As Integer = _GridView.SourceRowHandle
If _GridView.GetSelectedRows().Length = _GridView.RowCount Then
    TryCast(_GridView.ParentView, GridView).SelectRow(masterRowHandle)

winforms-reporting-create-grid-based-report/VB/ConvertGridToReportExample/Form1.vb#L50

vb
Next c
For r As Integer = 0 To gridView.RowCount - 1

See Also

BaseView.RowCount

CardView.RowCount

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace