RadGridView - Row Delete action Changes to Row Update action possible?

1 Answer 356 Views
GridView
Phong
Top achievements
Rank 1
Phong asked on 25 Sep 2021, 08:23 PM
I'm using Telerik RadGridView for WinForms.  Its data source is a table in a DataSet.  The grid view allows user to add, update, and delete rows.  Below is how the row update is done:

private void radGridView2_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
    if (e.OldRow == null)
    {
        return;
    }

    DataRowView dataRowView = e.OldRow.DataBoundItem as DataRowView;
    if (dataRowView != null)
    {
        DataRow dataRow = dataRowView.Row;
        if (dataRow.RowState == DataRowState.Modified)
        {                    
      tableAdapter.Update(dataRow);
        }
    }
}

What I would like to accomplish is when user press the DEL key on a row, the row is still removed from the grid view but not from the backend database table. Instead, I would like to have an Update on the database table row's colunm (MarkedForDeletion) with a new value.

I'm thinking about intercepting the delete events (UserDeletingRow, or UserDeletedRow, or ?), and then manipulate the DataRow object and then call the tableAdapter.Update(dataRow) as above.  What exactly do I need to do?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 27 Sep 2021, 10:58 AM

Hi Phong,

Deleting a row in the grid results in deleting an item inside the data source object. This behavior is expected and it is by design. Updating the database is application specific and it depends on the actual data and how it is fetched locally. The grid itself is not responsible for this job.

Your scenario is rather custom and it seems that you will need some special update logic. For example, you can consider checking for the RowState and if it is Detached or Deleted update the database according to your local scenario. Another solution would be to setup the grid in unbound mode. This approach may require some more work to get all changes for a particular row but it will give you freedom and more flexibility when you update the database.

I hope this will help. Let me know if you need further assistance.

Regards,
Hristo
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Phong
Top achievements
Rank 1
commented on 27 Sep 2021, 03:42 PM

Thank you Hristo!
Tags
GridView
Asked by
Phong
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or