Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2006

Tip: Looking for answers? Try searching our database.

DataBinding Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin - 24 Jan 2006 14:55 GMT
Hello,

i have a custom collection implementing IList. this collection holds custom
objects. my binding object is the collection. i implemented the
PropertyChanged events in my custom object.

example:
txtMyControl.DataBindings.Add("Text", myCustomCollection, "MyPropertyName");

the problem is, that the text editor isn't refreshed when the property
changed. the following works:

txtMyControl.DataBindings.Add("Text", myCustomCollection[sKey],
"MyPropertyName");

do anybody know why the second works or why the first don't work?

thanx!
Bart Mermuys - 24 Jan 2006 15:39 GMT
Hi,

> Hello,
>
[quoted text clipped - 11 lines]
> txtMyControl.DataBindings.Add("Text", myCustomCollection[sKey],
> "MyPropertyName");

Custom object's notify the UI differently then custom lists.

In NET1.1, custom object's fire a "PropName+Changed" event and in NET2.0
custom object's can fire INotifyPropertyChanged.PropertyChanged.

In NET1.1, custom lists must implement IBindingList and fire
IBindingList.ListChanged when one of its items have changed.  This means you
need to implement this yourself, eg. make it so that the custom objects know
which custom list they belong to, then when one of the object's properties
changes, the object calls a method on the custom list which will fire
IBindingList.ListChanged(ItemChanged).

The same is true for NET2.0, BUT you can use BindingList<T> as a custom list
or as a basis for a custom list.  A BindingList<T> will catch the
INotifyPropertyChanged.PropertyChanged fired by any of it's objects and then
fire IBindingList.ListChanged (resulting in a correct update of UI).

Example (NET2.0)

public class CustomObject : INotifyPropertyChanged
{
 private string name;
 public PropertyChangedHandler PropertyChanged;

 public string Name
 {
   get { return name; }
   set
   {
     if ( name != value )
     {
       name = value;
       if ( PropertyChanged!=null)
        PropertyChanged(this, new PropertyChangedEventArgs("Name");
     }
   }
 }
}

public class CustomList : BindingList<CustomObject>
{
   // The BindingList implements IBindingList and will fire
   // IBindingList.ListChanged when one of the items
   // fired INotifyPropertyChanged.PropertyChanged.
   // It also includes typical typed collection methods.
}

CustomList cl = new CustomList();

cl.Add ....
cl.Add....

txtMyControl.DataBindings.Add("Text", cl, "Name");

HTH,
Greetings

> do anybody know why the second works or why the first don't work?
>
> thanx!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.