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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Deleting records using a data bound business object

Thread ID:

Created:

Updated:

Platform:

Replies:

72998 Apr 15,2008 03:14 PM UTC Apr 24,2008 09:50 PM UTC WinForms 1
loading
Tags: Grouping
James Evans
Asked On April 15, 2008 03:14 PM UTC

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



Sri Rajan [Syncfusion]
Replied On 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




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

;