0

I have a Gridview within a WinForm. I have a column of that gridview that I edit. I can click in a cell edit and hit enter to complete the editing on every cell except the one in the last row. The "enter" key does nothing when there is no row below to change to. I have tried to use the _keyPress and _keyDown events to change the "enter" key to a tab which would allow for the user to go about as normal with editing and hit enter to submit their changes.

If anyone has any input I would appreciate it.

Also Currently when i select a cell it goes into edit mode, and when the cell is no longer selected i call my endedit event and submit any changes.

I tried adding an EditingControlShowingEvent the below code was to try and assign an event to the control being edited in hopes it would call the keydown event. But it still did not.

private void dg_EditingControlSHowing(object sender,DataGridViewEditingControlShowingEventArgs e)
{
e.Control.KeyDown += new KeyEventHandler(Control_KeyDown);
}                                                              
private void Control_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyData == Keys.Enter)
{
 this.ProcessTabKey(true);
}
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
RicketyBowby
  • 63
  • 1
  • 4

1 Answers1

0
if(e.KeyData == Keys.Enter)
{
this.ProcessTabKey(true);
  if(datagrid1.Rows[grid.Rows.Count - 1].Selected == true){
    //run your event here
  }
}

This is about the only thing I can come up with. It would check that your last row is selected so that it can then go about another process, say for example you could get it to add a new row when it hits that bit.

I'm not 100% sure that's what you need but I hope it helps with a method or gives you an idea

Adsy2010
  • 525
  • 6
  • 23