Groups | Blog | Home
all groups > dotnet windows forms databinding > december 2005 >

dotnet windows forms databinding : What is the event for Item Update?


amolkasbekar NO[at]SPAM gmail.com
12/21/2005 11:43:47 PM
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?

Thanx in advance,
Amol.
amolkasbekar NO[at]SPAM gmail.com
12/22/2005 5:57:35 AM
Thanx for your reply Joanna.. This is what I want to implement
For e.g. if the column in the grid corresponds to the property name in
the person object in the personCollection which has been binded, when
the user changes the value of the cell in the column and the cell then
loses focus (from a tab out by the user or clicking some place else) I
want to capture the new value of the property from corresponding object
in the collection and perform some action (in this case update the
column corresponding to the property to the database)

Thanx in advance
Amol.
Joanna Carter [TeamB]
12/22/2005 7:50:22 AM
<amolkasbekar@gmail.com> a écrit dans le message de 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?

Depending on what you want to do, you could use Validating.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Bart Mermuys
12/22/2005 3:10:08 PM
Hi,

[quoted text, click to view]

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]

AddThis Social Bookmark Button