Hi @StewartBW ,
You should replace DataGridView.SelectedRows.Count
with DataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected)
when you need to get the number of selected rows, as the GetRowCount
method is more efficient for this purpose.
However, for the total number of rows, you should not replace DataGridView.Rows.Count
with DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible)
. The Rows.Count
property already gives you the total number of rows, while GetRowCount(DataGridViewElementStates.Visible)
will give you the count of rows that are currently visible.
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.