i wanted to show the message "You have not selected any rows" if the selected rows is 0.
But, even i click the first row in datagridview, and i trace it, the selected rows always gave me 0.
Why is it like that?
Here is the code:
MessageBox.Show(dataGridView1.SelectedRows.Count.ToString()); // below function always run, because the selected rows always 0, even i clicked the first row in datagridview (when run the program)
if (dataGridView1.SelectedRows.Count == 0)
{
if (choice.comboBox1.Text == "English")
{
System.Media.SoundPlayer sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
sound.Play();
MessageBox.Show("You Have Not Selected Any Rows!", "Error");
}
}
else
{
DeleteDatabase(sender, e);
}
The MSDN says
The SelectionMode property must be set to FullRowSelect or RowHeaderSelect for the SelectedRows property to be populated with selected rows.
You need to set this property accordingly otherwise no SelectedRows.
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