Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, when a class implements <code>INotifyPropertyChanged</code>, the <code>BindingList&lt;T&gt;</code> class raises its <code>ListChanged</code> event on each <code>PropertyChanged</code> event with a <code>ListChangedEventArgs</code> object whose <code>ListChangedType</code> property is equal to <code>ItemChanged</code>.</p> <p>Armed with this knowledge, I feel you should be able to accomplish what you want. (Where <code>ListChangedType == ListChangedType.ItemChanged</code>, pass the object at index <code>NewIndex</code> of the <code>BindingList&lt;T&gt;</code> to your service.)</p> <hr> <p><strong>UPDATE</strong>: Below is a sample application I wrote to demonstrate that the <code>ListChanged</code> event <strong>is</strong> raised when an item is modified through the <code>DataGridView</code>:</p> <h3>The <code>CustomObject</code> class: a simple implementation of <code>INotifyPropertyChanged</code></h3> <pre><code>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 </code></pre> <h3>The <code>DataBindingTestForm</code> class: a basic <code>Form</code> class with a <code>DataGridView</code> bound to a <code>BindingList(Of CustomObject)</code></h3> <pre><code>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 </code></pre> <p>In running the above demo application, when I change the value in a cell of the <code>DataGridView</code> (e.g., from "John" to "George"), a message box appears with the following text:</p> <pre><code>ListChanged event fired. Index: 0, Value: George </code></pre> <p>Try this out for yourself and let me know if you run into any further problems.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload