Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a button that does an operation. but if my datgridview is empty or null it will prom a message saying it is null or empty.

What I have tried:

if (mydatagridview.rows.count == 0)
{
//message
}
but this is checking every row that I have what if I have tons of rows.is there other way for faster logic/code than this? thankss
Posted
Updated 16-Jun-18 19:48pm

1 solution

To check for null and empty:
if (mydatagridview == null || mydatagridview.Rows.Count == 0)
{
    // message
}


Rows.Count doesn't calculate the rows at the time of calling, but returns a value that is updated when adding and deleting rows. There is no problem calling it to check if the DataGridView is empty.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900