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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Delete Key - DataBound Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

13784 May 11,2004 01:10 AM UTC Dec 2,2004 10:15 AM UTC WinForms 5
loading
Tags: GridControl
Satish
Asked On May 11, 2004 01:10 AM UTC

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

Administrator [Syncfusion]
Replied On May 11, 2004 06:37 AM UTC

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;
}

Thiyagu
Replied On December 2, 2004 09:38 AM UTC

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;
>}
>

Administrator [Syncfusion]
Replied On December 2, 2004 09:48 AM UTC

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.

Thiyagu
Replied On December 2, 2004 10:05 AM UTC

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.

Administrator [Syncfusion]
Replied On December 2, 2004 10:15 AM UTC

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;