Danish Raza

Danish Raza

  • NA
  • 1
  • 1.1k

DataGridView Delete Problem

Jun 3 2015 5:05 AM
Datagridview control problem.I have Images to define my problem but i think editor is not support it.Anyway problem is that i have a DataGridView Control in VS2010 to add and delete data from grid, when i select row of grid to delete record then grid pointer select complete row, after i press delete button from keyboard then grid pointer convert into pensil pointer/edit thats why i cannot delete my row from datagridview, below events and code which i m using,it is working fine when i use mouse double click event. but i need to delete row on delete button.i have try keyup/key down evetns too may be i could not set any property or event.

Hide Copy Code
private void dgdSoilTexture_KeyDown ( object       sender,                                        KeyEventArgs e )     
{          if ( e.KeyCode == Keys.Delete )         
{         dgdSoilTexture.EditMode = DataGridViewEditMode.EditOnF2;         
if ( MessageBox.Show (                 "Are you sure you want to Delete this record?",                "",                 MessageBoxButtons.YesNo,                 MessageBoxIcon.Question,                 MessageBoxDefaultButton.Button2) == DialogResult.Yes )           
  {             dgdSoilTexture.Rows.RemoveAt ( dgdSoilTexture.CurrentRow.Index );             
}         
}     
}

Answers (1)