hey Geeks,
I have a datagridview in which i have one button column .. i am using it for selecting some values of that row.
what i want is when that button cell gets focus ,i press enter key (instead of clicking it by mouse) data of that row should be selected .help in guys.
here is my code
private void comboProname_TextChanged(object sender, EventArgs e) //combo box of product name
{ cmd = new SqlCommand("select P_batchno,P_min_stk,P_max_stk,P_vat from PRO where P_name='" + comboProname.Text + "'", conn);
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
if(comboBthNo.Text=="")
{ dataGridView3.Visible = true; //datagrid which has button column
int i = 0;
dataGridView3.Rows.Insert(i);
dataGridView3.Rows[i].Cells[0].Value = dr["P_batchno"].ToString();
tbMinstk.Text = dr["P_min_stk"].ToString();
tbMaxStk.Text = dr["P_max_stk"].ToString();
tbVAT.Text = dr["P_vat"].ToString();
}
}
conn.Close();
}
{ cmd = new SqlCommand("select P_batchno,P_min_stk,P_max_stk,P_vat from PRO where P_name='" + comboProname.Text + "'", conn);
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
if(comboBthNo.Text=="")
{ dataGridView3.Visible = true; //datagrid which has button column
int i = 0;
dataGridView3.Rows.Insert(i);
dataGridView3.Rows[i].Cells[0].Value = dr["P_batchno"].ToString();
tbMinstk.Text = dr["P_min_stk"].ToString();
tbMaxStk.Text = dr["P_max_stk"].ToString();
tbVAT.Text = dr["P_vat"].ToString();
}
}
conn.Close();
}
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ //for batchno I want dis all to be done on Enter key.
string p;
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
{
//TODO - Button Clicked - Execute Code Here
p = (dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString());
comboBthNo.Text = p;
}
}
{ //for batchno I want dis all to be done on Enter key.
string p;
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
{
//TODO - Button Clicked - Execute Code Here
p = (dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString());
comboBthNo.Text = p;
}
}
looking forward to ur help frens,thanks in advance

huang zhenhuaPosted Jul 21, 2014, 5:31 AM
private void dataGridView3_KeyDown(object sender, KeyEventArgs e) //use KeyDown
{
if (e.KeyCode == Keys.Enter)
{
string p;
if (dataGridView3.CurrentCell.ColumnIndex == 3)//3 is your button column's index
{
int i=dataGridView3.CurrentRow.Index;
p=dataGridView3.Rows[i].Cell[0].Value.ToString();
comboBthNo.Text=p;
}
}
}
hope it can help you,by the way,i'm come from China,my English is no very well,hope you can Read and understand this answer
varsha dodiyaPosted Jul 21, 2014, 5:40 AM