PC Review


Reply
 
 
csharpula csharp
Guest
Posts: n/a
 
      2nd Dec 2007


Hello,I am still having problems with list<object> binding. How can I
enforce that the gui binded to this list will be updated automatically
as soon as there is update in list values? Thank you very much!

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      2nd Dec 2007
List<T> doesn't support IBindingList/IBindingListView; switch to
BindingList<T> and you should get what you need. Note that this will
support additions/removals/swaps etc, but that property-notifications
(i.e. changes to specific properties of specific items) will only be
supported if your entity (T) implements INotifyPropertyChanged (and
raises property-change notifications as necessary). While individual
property events (PropertyAChanged, PropertyBChanged, etc) are
supported by some implementations, BindingList<T> only uses
INotifyPropertyChanged.

Marc
 
Reply With Quote
 
csharpula csharp
Guest
Posts: n/a
 
      4th Dec 2007


But how can I after implementing this interface inforce the binding list
of those items to be updated?

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      4th Dec 2007
Everything daisy-chains together. When the property value changes, you
raise the INotifyPropertyChangee.PropertyChanged event. That is
normally the end of what you need to implement.

For completeness, a bindable list (such as BindingList<T>) which
supports notification (IBindingList.SupportsChangeNotification) should
internally subscribe to (for example) the PropertyChanged event for
the items it holds, and (when it is raised) raise the
IBindingList.ListChanged event with ListChangeType of ItemChanged;
equally, it should raise the ListChanged event (with suitable
change-type) when items are added, removed or re-ordered. Luckily,
BindingList<T> does all of this for you, although it doesn't provide
the optional sort/etc features of IBindingList.
A binding-source / currency-manager will subscribe to the ListChanged
event, raising things like CurrentItemChanged, ItemChanged,
ListChanged, etc.
This will be further notified to any bindings, which will get the
value from the source. So through a potentially complex chain of smoke
and mirrors, the UI should indirectly receive word that a property
changed, and update itself.

A simple example of raising the PropertyChanged event follows.

Marc

class Person : INotifyPropertyChanged
{
public Person() { }
public Person(string name, DateTime dateOfBirth)
{
Name = name;
DateOfBirth = dateOfBirth;
}
private DateTime dateOfBirth;
private string name;

public DateTime DateOfBirth
{
get { return dateOfBirth; }
set { UpdateField(ref dateOfBirth, value, "DateOfBirth"); }
}
public string Name
{
get { return name; }
set { UpdateField(ref name, value, "Name"); }
}

public event PropertyChangedEventHandler PropertyChanged;

protected void UpdateField<T>(ref T field, T value, string
propertyName)
{
if (!EqualityComparer<T>.Default.Equals(field, value)) {
field = value;
if (PropertyChanged != null) PropertyChanged(this, new
PropertyChangedEventArgs(propertyName));
}
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bind data to gridview using custom data class? =?Utf-8?B?dmluZWV0YmF0dGE=?= Microsoft ADO .NET 5 17th Oct 2006 11:23 PM
how to bind Data to Grid view with custom data class. =?Utf-8?B?dmluZWV0YmF0dGE=?= Microsoft ADO .NET 0 16th Oct 2006 07:06 AM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 Microsoft ASP .NET 1 2nd Oct 2005 06:07 PM
User cannot load Data Access Page....fails to bind data. =?Utf-8?B?bWNuZWFs?= Microsoft Access VBA Modules 0 24th Nov 2004 05:37 PM
Bind different rows to different data sources in data grid AD Microsoft ASP .NET 1 23rd Aug 2003 11:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.