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
close icon

Deleting records using a data bound business object

I have a very simple grouping grid and I would like the users to be able to delete records from the grid any only apply these deleted to the database when a save button is pressed.

To achieve this so far I have a BindingList as the data source where T is my business object. When the delete happens the record is deleted from the BindingList so now I don't know which record needs to be deleted.

I could probably get round this by detecting when a record is removed from the BindingList and then having another list to hold the deleted records but I was hoping there would be a more graceful way to achieve this standard problem.

Would you let me know the recommended way of dealing with this issue.

I am thinking there might be a way of flagging a record as having been deleted so it doesn't appear in the grid when the grid is refreshed but it's still in my BindingList so I can apply this to the database when the save button is pressed.

(I know that datasets can do this but I would like to use a business object is I can)

Thanks
James



1 Reply

SR Sri Rajan Syncfusion Team April 24, 2008 09:50 PM UTC

Hi James,

Thank you for your patience.

To achieve this behaviour you need to derive the BindingList class and Override RemoveItem method. In RemoveItem method, you need to store the deleted records information in a new BindingList. You can access these deleted record information using GetDeletedList method. Here are the code snippet.

public class MyBindingList : BindingList
{
BindingList list = new BindingList();
protected override void RemoveItem(int index)
{
list.Add(this[index]);
Console.WriteLine(index.ToString());
base.RemoveItem(index);
}

//To get the deleted record list.
public BindingList GetDeletedList()
{
return list;
}
}



private void button1_Click(object sender, EventArgs e)
{
BindingList list = bl.GetDeletedList();
foreach (CustomClass obj in list)
{
Console.WriteLine(obj.ID);
}
}



Here is the sample code which implements this task.
http://websamples.syncfusion.com/samples/Grid.Windows/I73051/main.htm

Please let me know if this helps.

Best Regards,
Srirajan




Loader.
Live Chat Icon For mobile
Up arrow icon