Well, when a class implements INotifyPropertyChanged
, the BindingList<T>
class raises its ListChanged
event on each PropertyChanged
event with a ListChangedEventArgs
object whose ListChangedType
property is equal to ItemChanged
.
Armed with this knowledge, I feel you should be able to accomplish what you want. (Where ListChangedType == ListChangedType.ItemChanged
, pass the object at index NewIndex
of the BindingList<T>
to your service.)
UPDATE: Below is a sample application I wrote to demonstrate that the ListChanged
event is raised when an item is modified through the DataGridView
:
The CustomObject
class: a simple implementation of INotifyPropertyChanged
Imports System.ComponentModel
Public Class CustomObject
Implements INotifyPropertyChanged
Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
OnPropertyChanged("Name")
End Set
End Property
Protected Sub OnPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
The DataBindingTestForm
class: a basic Form
class with a DataGridView
bound to a BindingList(Of CustomObject)
Imports System.ComponentModel
Public Class DataBindingTestForm
Private WithEvents _customObjects As New BindingList(Of CustomObject)
Private Sub DataBindingTestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As New CustomObject
obj.Name = "John"
_customObjects.Add(obj)
obj = New CustomObject
obj.Name = "Bill"
_customObjects.Add(obj)
MainDataGridView.DataSource = _customObjects
End Sub
Private Sub _customObjects_ListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs) Handles _customObjects.ListChanged
If Not e.ListChangedType = ListChangedType.ItemChanged Then Return
Notify("ListChanged event fired. Index: {0}, Value: {1}", e.NewIndex, _customObjects(e.NewIndex).Name)
End Sub
Private Sub Notify(ByVal format As String, ByVal ParamArray args() As Object)
MsgBox(String.Format(format, args))
End Sub
End Class
In running the above demo application, when I change the value in a cell of the DataGridView
(e.g., from "John" to "George"), a message box appears with the following text:
ListChanged event fired. Index: 0, Value: George
Try this out for yourself and let me know if you run into any further problems.