I am trying to write a logic where upon selection of a row it should fill the form based on the value of the row selected from the datagrid view...
But it is giving "select one row" message only on selecting few cells only
and also i am not able to fill up the form even upon selection of a row
kindly help
this is my code
But it is giving "select one row" message only on selecting few cells only
and also i am not able to fill up the form even upon selection of a row
kindly help
this is my code
Code:
private void kryptonDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int selectedCount = kryptonDataGridView1.SelectedRows.Count;
if (selectedCount != 1)
{
MessageBox.Show("Please select one row");
return;
}
else
{
string block_id = Convert.ToString(kryptonDataGridView1.SelectedRows[0].Cells[0].Value);
MessageBox.Show(block_id);
try
{
connectioncls c = new connectioncls();
SqlConnection cn = c.connection();
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT block_name FROM block WHERE block_id = '" + block_id + "'");
cmd.Connection = cn;
string ename = Convert.ToString(cmd.ExecuteScalar());
textBox7.Text = ename;
cn.Close();
cn.Open();
SqlCommand cmd1 = new SqlCommand("Select description from block where block_id = '" + block_id + "'");
cmd1.Connection = cn;
string mob_num = Convert.ToString(cmd1.ExecuteScalar());
textBox6.Text = mob_num;
cn.Close();
textBox8.Text = block_id;
}
catch (Exception exp)
{
MessageBox.Show("Connection error:" + exp.ToString());
}
}
}
Comment