We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Delete Key - DataBound Grid

How to trap the Del Key when user presses it? I need to show up messge box before user deletes the current record or selected multiple records. Thanks Satish

5 Replies

AD Administrator Syncfusion Team May 11, 2004 02:37 AM

You can use the RowsDeleting event to query whether rows should be deleted.
private void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
	if(MessageBox.Show("Delete? ", "", MessageBoxButtons.YesNo) == DialogResult.No)
		e.Cancel = true;
}


TH Thiyagu December 2, 2004 04:38 AM

Hi Clay, I just searched for handling the Del key press event. I tried with the rows deleting event. But when I say yes, Its deleting the current row and also it hides the row next to it. FYI.. I''m having a separate Delete button in my form for Deleting a row. I''m calling this event in the rows deleting event of the grid. Plz reply as early as possible.. Its really urgent.. Thanks in Advance Thiagu. >You can use the RowsDeleting event to query whether rows should be deleted. > >
>private void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e)
>{
>	if(MessageBox.Show("Delete? ", "", MessageBoxButtons.YesNo) == DialogResult.No)
>		e.Cancel = true;
>}
>


AD Administrator Syncfusion Team December 2, 2004 04:48 AM

You did not say what kind of grid you are using, and what code you are using to try to delete the row in your button handler. This information would have been helpful. As a guess, I assume you are using a GridDataBoundBound and in your button handler you are using this.gridDataBoundGrid1.Binder.RemoveRecords to remove the record. If this is what you are doing, then you should ask you confirmation question in your button handler, and only call the this.gridDataBoundGrid1.Binder.RemoveRecords method if the user confirms. In this case, you would not need code in RowDeleting. this.gridDataBoundGrid1.Binder.RemoveRecords accepts a zero based position index. So, if you want to delete teh record at grid row index 5, then you need to pass this method the value 4. Normally, you would use int position = this.grid.Binder.RowIndexToPosition(gridRowIndex); to map a grid row index to a position in teh datasource.


TH Thiyagu December 2, 2004 05:05 AM

Thanks a lot for the immediate reply Clay. And yes, I''m using Grid Data Bound Grid. And in Delete ''button'' press event, I''m deleting from the Data base by passing the Delete Query and then I''m reloading the Grid again by fetching fresh data from the Data base. The user will be able to select only one row. In Rows deleting event, I''m using the following code private void DataBoundGrid__RowsDeleting(object sender, Syncfusion.Windows.Forms.Grid.GridRowRangeEventArgs e) { System.EventArgs e1 = new EventArgs(); this.deleteButton__Click(sender,e1); if(responseDelete_ =="No") e.Cancel = true; } Please help.. Thiagu. >You did not say what kind of grid you are using, and what code you are using to try to delete the row in your button handler. This information would have been helpful. > >As a guess, I assume you are using a GridDataBoundBound and in your button handler you are using this.gridDataBoundGrid1.Binder.RemoveRecords to remove the record. > >If this is what you are doing, then you should ask you confirmation question in your button handler, and only call the this.gridDataBoundGrid1.Binder.RemoveRecords method if the user confirms. In this case, you would not need code in RowDeleting. > >this.gridDataBoundGrid1.Binder.RemoveRecords accepts a zero based position index. So, if you want to delete teh record at grid row index 5, then you need to pass this method the value 4. Normally, you would use > >int position = this.grid.Binder.RowIndexToPosition(gridRowIndex); > >to map a grid row index to a position in teh datasource.


AD Administrator Syncfusion Team December 2, 2004 05:15 AM

Uisng 2.1.0.9, things seem to work as expected in this sample. I suspect it is something specific to your implementation that is causing this problem. RowsDeleting_742.zip

Loader.
Live Chat Icon For mobile
Up arrow icon