Hi,
[quoted text, click to view] <amolkasbekar@gmail.com> wrote in message
news:1135237427.887848.257980@z14g2000cwz.googlegroups.com...
>I am building a custom data binding control that derives from
> BindingList<of T> and provides transparent persistence mechanism of the
> objects to the database like a datatable. To do this I override the
> appropriate events in my custom control class.
> e.g. adding object to the datagridview adds it directly to the table in
> the db. To do this I override the AddNewCore method.
>
> Which is the event to capture a change in a cell content? For e.g. a
> user changes the value of a column say 'Name' in the grid and then hits
> tab to go to the next column, how to capture this event?
Keep in mind that within the context of your BindingList<T> there is no
CurrentItem, there is only a CurrentItem within WinForms
(BindingSource/CurrencyManager).
But if you use a BindingList<T> and T implements INotifyPropertyChanged
(which it really should anyway) then the BindingList<T> will run
OnListChanged(ItemChanged) when _any_ of the item properties has changed,
example:
public class CustomObject : INotifyPropertyChanged
{
private string name;
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public string Name
{
get
{
return name;
}
set
{
if (name != value)
{
name = value;
OnPropertyChanged("Name");
}
}
}
protected virtual void OnPropertyChanged(string PropName)
{
if (PropertyChanged != null)
PropertyChanged(this,
new PropertyChangedEventArgs(PropName));
}
}
public class CustomCollection : BindingList<CustomObject>
{
protected override void OnListChanged(ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemChanged)
{
// co is the object whose property has changed
CustomObject co = this[e.OldIndex];
Console.WriteLine("Item[{0}] Property '{1}' Changed",
e.OldIndex,
e.PropertyDescriptor.Name);
}
// don't forget to call the base
base.OnListChanged(e);
}
}
HTH,
Greetings
[quoted text, click to view] >
> Thanx in advance,
> Amol.
>