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 Data Binding / August 2007

Tip: Looking for answers? Try searching our database.

What interfaces do I need to implement for complete databinding?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Juan Dent - 24 Aug 2007 21:24 GMT
Hi,

I want to have collections of objects that are data-bindable to datagrids
but also editable and sortable, etc., the full functionality.

Also, I want the objects themselves to be data-bindable as well, to controls
such as textboxes and checkboxes and radiobuttons, etc.

Additionally, I want to be able to add these objects to the toolbox so I can
drag and drop into Windows Forms.

What interfaces do I need to implement to accomplish all this?
any good examples?
Signature

Thanks in advance,

Juan Dent, M.Sc.

Tim Van Wassenhove - 24 Aug 2007 21:48 GMT
> What interfaces do I need to implement to accomplish all this?
> any good examples?

I find the following two urls to good resources:
http://msdn2.microsoft.com/en-us/library/41e17s4b.aspx
http://www.dotnet247.com/247reference/msgs/26/133852.aspx

Signature

Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/>

Linda Liu [MSFT] - 27 Aug 2007 06:44 GMT
Hi Juan,

Generally speaking, for a collection, to support the general functionality
of data binding, such as sorting capabilities, change notification and
filtering, you need to implement the IBindingListView, the IBindingList,
the ICollection and the IEumerable interfaces.

.NET 2.0 provides the BindingSource class, which has implmented all the
above interfaces and serves as a powerful data source. You can use the
BindingSource as the data source in your project.

> Also, I want the objects themselves to be data-bindable as well, to
controls such as textboxes and checkboxes and radiobuttons, etc.

You can bind any property of the objects to the WinForms controls, such as
TextBox, CheckBox or RadioButton without implementing any interfaces.
However, to update the data source when the value of the control property
changes, you should specify the DataSourceUpdateMode parameter in the
ControlBindingsCollection.Add method. The following is a sample:

this.textBox1.DataBindings.Add("Text", myObject,
"Name",true,DataSourceUpdateMode.OnPropertyChanged);

On the other hand, to update the control property value when the value in
the data source changes, you should implement the INotifyPropertyChanged
interface for the object's class. The following is a sample:

class Person:INotifyPropertyChanged
{
          private string name;
          public string Name
           {
               get { return name; }
               set
               {
                   if (value != name)
                   {
                       name = value;
                       propertyChanged(this, new
PropertyChangedEventArgs("Name"));
                   }
               }
          }
        private event PropertyChangedEventHandler propertyChanged;

           #region INotifyPropertyChanged Members

           event PropertyChangedEventHandler
INotifyPropertyChanged.PropertyChanged
           {
               add { propertyChanged += value; }
               remove { propertyChanged -= value; }
           }

           #endregion
       }
}

> Additionally, I want to be able to add these objects to the toolbox so I
can drag and drop into Windows Forms.

If your components are defined by a project in the currently open solution,
they will automatically appear in the Toolbox, with no action required by
you. You can also manually populate the Toolbox with your custom components
by using the Choose Toolbox Items Dialog Box (Visual Studio), but the
Toolbox takes account of items in your solution's build outputs with all
the following characteristics:

a. Implements IComponent;
b. Does not have ToolboxItemAttribute set to false;
c. Does not have DesignTimeVisibleAttribute set to false.

For more information on "Automatically Populating the Toolbox with Custom
Components", you may refer to the following MSDN document:
http://msdn2.microsoft.com/en-us/library/fw694kde(VS.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 29 Aug 2007 07:45 GMT
Hi Juan,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

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.