I want to catch the user hitting enter key when is in the cell edit mode. After that I am trying to show another form so the user can choose a value from it:
private void dgDetalji_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && dgDetalji.SelectedCells.Count == 1)
{
var selectedCell = dgDetalji.SelectedCells[0];
if (selectedCell.OwningColumn.Name.ToLower() == "šifra")
{
using (ModalForm frm = new ModalForm())
{
var aaa = new ucEditor
{
Parent = frm,
_query = "Select * From proizvodi",
_where_statement = "where šifra like '{0}%'",
_order_by_clause = "order by naziv"
};
frm.Controls.Add(aaa);
aaa.tbSearch.Text = selectedCell.Value.ToString();
aaa.setOleDbDataAdapter(connection);
Utils.setEditor(aaa);
aaa.Dock = DockStyle.Fill;
frm._Click_refresh_on_load = true;
frm.ShowDialog();
}
}
e.Handled = true;
}
}
This only works when the cell is NOT in cell edit mode. How to catch ENTER key pressed in cell edit mode on datagridview?
UPDATE:
I will instruct the user to press CTRL + ENTER at the end of editing and then again press ENTER so dgDetalji_KeyDown will work.