選択した行が0の場合、「行が選択されていません」というメッセージを表示したかった.
しかし、datagridview の最初の行をクリックしてトレースしても、選択した行は常に 0 になりました。
なぜそうなのですか?
コードは次のとおりです。
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);
}