Detecting BindingSource "row deleted" event

  • Thread starter Thread starter Tomasz J
  • Start date Start date
T

Tomasz J

Hello Developers,

I have a DataGridView and BindingNavigator controls bound to a BindingSource
control.
User can delete a record using different methods: by pressing the DEL key,
pressing BindingNavigator Delete button. I may also want to add some other
methods calling BindingSource.RemoveCurrent().

How do I detect BindingSource "row deleted" event and get deleted row
reference, so I can post changes?

I would appreciate any hints.

Tomasz J
 
Hi Tomasz,

Getting the row deletion notification is easy. You may use
BindingSource.ListChanged event for this task. In this event, you may check
if the current list change type is ListChangedType.ItemDeleted. The code
snippet below demonstrates the logic:

private void bindingSource1_ListChanged(object sender, ListChangedEventArgs
e)
{
if (e.ListChangedType == ListChangedType.ItemDeleted)
{
}
}

However, to get the current deleted rows, there is no simple and easy way.
BindingSource.ListChanged is a completed event which fires after the row
deletion is done. When this event is firing, the row is already deleted
from the DataView. By default, the DataView will filter out these deleted
rows with DataView.RowStateFilter property.

The workarounds we have are:
1. If you are binding to the DataTable/DataSet, you may use
DataTable.RowDeleting event to get the deletion notification. And the
DataRowChangeEventArgs.Row will point to the current deleting row.
2. You have to catch all the deletion operations at various UI controls ,
such as DataGridView, BindingNavigator etc.. and find out the current
deleting rows

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Jeffrey,

Catching all the deletion operations at various UI controls is precisely
what I am trying to avoid.

But I did not think about using DataTable.RowDeleting event - thank you.

BindingSource.ListChanged is useless for this purpose.
I think this BindingSource control functionality should really be improved.
Currently it is good only for MSDN demos.

Thanks,

Tomasz
 
Hi Tomasz,

Thank you for the feedback.

Yes, I agree the BIndingSource control model is not rich enough for your
special requirement. I would recommend you to submit a suggestion feedback
in the link below. The request will finally file in the Winform dev team
database for consideration:
https://connect.microsoft.com/VisualStudio?wa=wsignin1.0

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Tomasz,

Thank you for the feedback.

You may monitor this connect link and wait for the response from the dev
team. Note: the dev team does not have the same policy as MSDN newsgroup
support, so they may take a long time to response.

Anyway, if you need further help, please feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Well, the resolution, if ever provided, may take two full .Net Framework
releases.



Tomasz J
 
Hi Tomasz,

Yes, this type of design feature request has gone out of the newsgroup
support decision. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top