Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Deleting rows in Winforms Datagrid
 

Deleting rows in Winforms Datagrid

Hi,

I am working on a C# Winforms application which uses Datagrid(.Net 1.1 version).
The application has got a button named "Delete" and on clicking of this button, the rows selected in the datagrid should be deleted.

Can anyone please help me out in achieving this...?


Thanks in advance...!

Regards,
livehed

livehedfsdfsd  Thursday, May 04, 2006 6:20 AM

Hi,

Try with this.....

  • First get the selected row index from the DataGrid
  • Cast the DataGrid source to the DataTable
  • Use the RemoveAt method to remove the row at the specified index.

Code Snippet:

//get the current row index
int rowIndex = DataGrid1.CurrentRowIndex;
//Removing the mapping from the datagrid
((DataTable)DataGrid1.DataSource).Rows.RemoveAt(rowIndex);

I hope this will solves your problem.....

thnkx,

Pesani

maheshkrp  Thursday, May 04, 2006 7:37 AM

dgDataGrid.Focus()

SendKeys.Send("{Del}")

vkh75  Thursday, May 04, 2006 7:52 AM

You can use google to search for other answers

Custom Search

More Threads

• Making a textbox column in a grid look up a value
• Confirming row deletions on datagridview
• Table names
• Format datagridview column but avoid CellFormatting event
• Check datagridview last row
• Datagrid problem
• DataGrid currency problem?
• datagridview - cellformat
• Searching or ordering columns in the dataset designer
• bindingNavigator1.BindingSource = (BindingSource)((DGV)sender).DataSource;