0

I went into problem: I have two DataGridView on my form MAIN and SUB, now here is what I want to do that if MAIN DataGridView cell is in edit mode and user press the down arrow then instead of going down to next row in MAIN DataGridView it should step to next row in SUB DataGridView

I have created an event on EditingControlShowing by handling the PreviewKeyDown but it works only if there is one row in MAIN DataGridView or i am on the Last row in MAIN dataGridView but if there are more then one row in MAIN DataGridView then if i press Arrow Up or Arrow Down it moves through MAIN DataGridView Rows only.

I have tried to control it at DataGridView peviewKey but arrow keys does not register there, also Arrow Keys does not register at DataGridView KeyDown and keypress while in edit mode

they are registered at keyup of DataGridView but at this point it do two thing move the rows down or up in both dataGridViews

what I want that if MAIN DataGridView cell is in editmode and up or down arrow key are pressed then it only change the row in SUB DataGridView not in main DataGridView

Any Ideas!

Nazmul
  • 575
  • 3
  • 18

2 Answers2

1

Have you tried programmatically selecting rows in the sub dataGridView? You can try getting the index of the selected row in the sub grid when the Main PreviewKeyDown event fires and then selecting the next sub dataGridView row like this for example:

subDataGridView.Rows(index).Selected = False
subDataGridView.Rows(index + 1).Selected = True

or maybe

subDataGridView.CurrentCell = DataGridView1.Rows(index + 1).Cells(0);
djerinic
  • 36
  • 4
  • Yes, i did that, but it only work if cell is in non-edit mode, but if cell is in edit mode then this event won't register arrow keys – MUHAMMAD WAQAS AZIZ May 22 '15 at 09:54
  • Have you tried the [EditingControlShowing](https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.editingcontrolshowing.aspx) event? More info in this question, looks like something you could use: http://stackoverflow.com/questions/8538120/cell-in-editmode-doesnt-fire-onkeydown-event-in-c-sharp – djerinic May 22 '15 at 11:01
  • the matter is resolved by overriding the dataGridView and making a custom column found solution here : http://weblogs.asp.net/rweigelt/1647400 Worked like a charm. – MUHAMMAD WAQAS AZIZ May 22 '15 at 13:33
0

the matter is resolved by overriding the "dataGridView" and making a custom column found solution here : enter link description here Worked like a charm.