all groups > dotnet windows forms databinding > august 2007 >
You're in the

dotnet windows forms databinding

group:

What interfaces do I need to implement for complete databinding?


What interfaces do I need to implement for complete databinding? Juan Dent
8/24/2007 1:24:19 PM
dotnet windows forms databinding:
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?
--
Thanks in advance,

Juan Dent, M.Sc.
Re: What interfaces do I need to implement for complete databinding? Tim Van Wassenhove
8/24/2007 1:48:15 PM
[quoted text, click to view]

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


--
Kind regards,
RE: What interfaces do I need to implement for complete databinding? v-lliu NO[at]SPAM online.microsoft.com
8/27/2007 12:00:00 AM
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.

[quoted text, click to view]
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
}
}

[quoted text, click to view]
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.
RE: What interfaces do I need to implement for complete databinding? v-lliu NO[at]SPAM online.microsoft.com
8/29/2007 12:00:00 AM
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
AddThis Social Bookmark Button