I have a datagridview which gets filled with data returned from a linq query. If the query returns no results I want to display a messagebox. Is there a way of checking to see if the datagridview is empty?
Regards
I have a datagridview which gets filled with data returned from a linq query. If the query returns no results I want to display a messagebox. Is there a way of checking to see if the datagridview is empty?
Regards
You can know if it' empty by checking the number of rows in the DataGridView. If myDataGridView.Rows.Count == 0 then your DataGridView is empty.
You can check the Rows.Count property of the datagridview.
Although you might also want to look into the EmptyDataText property of the DataGridView. It might save you showing a messagebox.
Based on the Linq results, you can hide the datagridview and show some other control (like a Literal or something) that shows the message. If you want some sort of messagebox popup, you'd need to throw some JavaScript in there.