Currently i have the following:
if (dataGridView1.Rows.Count == 0)
{
MessageBox.Show("EMPTY");
}
else
{
using (var soundPlayer = new SoundPlayer(@"c:\Windows\Media\chimes.wav"))
{
soundPlayer.Play(); // can also use soundPlayer.PlaySync()
}
}
My grid view looks like this:

But it seems to go to the else statement and make the sound. I need it to NOT make a sound if there is no data in the rows of the gridview.
According to the comment, you have:
dataGridView1.DataSource = BS;
where BS is BindingSource, so you can use its BindingSource.Count property.
So somewhere in the code:
var bindingSource = dataGridView1.DataSource as BindingSource;
if(bindingSource.Count == 0) {
MessageBox.Show("EMPTY");
}
You also check this when populate gridview.. like this
DataSet studentsList = students.GetAllStudents();
bool empty = IsEmpty(studentsList);
if(empty) {
MessageBox.Show("EMPTY");
}
else {
using (var soundPlayer = new SoundPlayer(@"c:\Windows\Media\chimes.wav"))
{
soundPlayer.Play();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With