0 out of 2 rated this helpful - Rate this topic

DataGridViewRowCollection.GetRowCount Method

Note: This method is new in the .NET Framework version 2.0.

This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Returns the number of DataGridViewRow objects in the collection that meet the specified criteria.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int GetRowCount (
	DataGridViewElementStates includeFilter
)
public int GetRowCount (
	DataGridViewElementStates includeFilter
)
public function GetRowCount (
	includeFilter : DataGridViewElementStates
) : int

Parameters

includeFilter

A bitwise combination of DataGridViewElementStates values.

Return Value

The number of DataGridViewRow objects in the DataGridViewRowCollection that have the attributes specified by includeFilter.
Exception typeCondition

ArgumentException

includeFilter is not a valid bitwise combination of DataGridViewElementStates values.

The following code example illustrates the use of this method to get the number of selected rows.

private void selectedRowsButton_Click(object sender, System.EventArgs e)
{
    Int32 selectedRowCount =
        dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
    if (selectedRowCount > 0)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        for (int i = 0; i < selectedRowCount; i++)
        {
            sb.Append("Row: ");
            sb.Append(dataGridView1.SelectedRows[i].Index.ToString());
            sb.Append(Environment.NewLine);
        }

        sb.Append("Total: " + selectedRowCount.ToString());
        MessageBox.Show(sb.ToString(), "Selected Rows");
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.