How can I tell if at least one dataGridView row is selected c#
.net, c#, datagridview, winforms
Solution
You simply remove the parenthesis after the "Count" keyword. It should look like this:
if (Convert.ToInt32(dataGridView1.Rows.Count) > 0)
{
//It is not empty
}
int c = dataGridView1.SelectedRows.Count; //remove parenthesis here
if (c>0)
{
//there is a row selected
}
Problem
I have a program that takes a value from the selected row in a dataGridView and passes it to a function. However, the gridView could be empty or could not have a row selected. I took care of the empty Grid, but I was wondering if there is a way if I can tell if any row is selected. I tried this: ``` if (Convert.ToInt32(dataGridView1.Rows.Count) > 0) { //It is not empty } int c = dataGridView1.SelectedRows.Count(); //this line gives me an error if (c>0) { //there is a row selected } ``` Do you know how can I solve this?