DataGridViewRowCollection.GetRowCount Method
.NET Framework 2.0
Note: This method is new in the .NET Framework version 2.0.
Assembly: System.Windows.Forms (in system.windows.forms.dll)
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.FormsAssembly: System.Windows.Forms (in system.windows.forms.dll)
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.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.