I am using datagridview in winform.
If I press the enter key the selection is moved on row wise. But I want to execute some code which i write below:
try
{
int dispin = dataGridView1.CurrentCell.OwningColumn.DisplayIndex;
if (dispin == 0)
{
string cellval = dataGridView1.CurrentCell.Value.ToString();
returnParam = cellval;
this.Close();
}
else
{
int rowIndex = dataGridView1.CurrentCell.RowIndex;
int colIndex = dataGridView1.CurrentCell.ColumnIndex;
colIndex = colIndex - 1;
string cellval = dataGridView1[colIndex, rowIndex].Value.ToString();
// MessageBox.Show(cellval1+cellval2+cellval3);
returnParam = cellval;
this.Close();
//textBox1.Text = cellval;
}
}
catch
{
MessageBox.Show("Select a Record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//this.Close();
}
How to do this?
I am trying key down event, but it affect all key, please help me.
Use
datagridview.KeyPressLike: