i have a datagridview that has 6 column, i want to add a new row every time i press "Tab" button (only) on the last cell of the column, i used the code bellow to prevent adding row everytime i write cell value
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Rows.Add();
i have already use keypress event on cell[5] (last cell) but it does not work, last cell was set to read only
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 5)
{
if (e.KeyChar == (char)Keys.Tab)
{
dataGridView1.Rows.Add();
}
}
}
thanks for your time, sorry about my english anyway
This will add a
Row
if and only if the current cell is the last one in theDGV
and the user pressesTab
.(Note that (obviously) the user now can't tab out of the
DGV
, except by backtabbing over the first cell..)Any attempt to use any of the Key events of the
DGV
will eventually leave theDGV
instead of adding aRow
..