Click here to Skip to main content
15,614,138 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friend,
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.

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?",
               MessageBoxDefaultButton.Button2) == DialogResult.Yes )
            dgdSoilTexture.Rows.RemoveAt ( dgdSoilTexture.CurrentRow.Index );
Updated 31-May-15 16:43pm
gggustafson 31-May-15 22:45pm    
what is the exact wording of the message?
Maciej Los 1-Jun-15 9:22am    
And what's an issue?
vinayvraman 1-Jun-15 22:58pm    
What is the data source that is bound to the grid view?
Have you tried selecting the row by clicking on the row header? If yes, then delete should automatically work if the data source is say DataTable. You do not have to handle the delete event explicitly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900