views:

1318

answers:

3

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

+3  A: 

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.

Meta-Knight
A: 

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.

Brandon
A: 

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.

mgroves
can't see why jscript would be needed at all, ever
Goober