.net - checking if gridview is empty using c# -


currently have following:

if (datagridview1.rows.count == 0) {     messagebox.show("empty"); } else {     using (var soundplayer = new soundplayer(@"c:\windows\media\chimes.wav"))     {         soundplayer.play(); // can use soundplayer.playsync()     } } 

my grid view looks this:

enter image description here

but seems go else statement , make sound. need not make sound if there no data in rows of gridview.

according comment, have:

datagridview1.datasource = bs; 

where bs bindingsource, can use bindingsource.count property.

so somewhere in code:

var bindingsource = datagridview1.datasource bindingsource;  if(bindingsource.count == 0) {   messagebox.show("empty"); }