Databinding question

  • Thread starter Thread starter Norm Dotti
  • Start date Start date
N

Norm Dotti

I have a user control that I drop to windows forms. I also
have typed dataset that is defined in the windows form
project. I want to bind the textboxes within the
usercontrol to a datatable field in this typed dataset.
I found the following old posting on this issue. But what
happens is, this property is not written to codebehind of
the form if it's set. So when I run the program it clears
the binding info. What do I have to do to make this work?

/*
Hello Colin,

You can export the DataBindings property of the child
control via property.
Since the DataBindings property is read only, you may need
to write some
code to handle set method of the property. This is a
sample code:

public System.Windows.Forms.ControlBindingsCollection
textBindings
{
set
{
System.Windows.Forms.ControlBindingsCollection bindings;
bindings =
(System.Windows.Forms.ControlBindingsCollection)value;
textBox1.DataBindings.Clear();
foreach(Binding b in bindings)
textBox1.DataBindings.Add(b);
}
get
{
return textBox1.DataBindings;
}
}

Hope it helps.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and
confers no rights.
You assume all risk for your use. 2001 Microsoft
Corporation. All rights
reserved.
*/

Thanks
 
Hi Norm,
To make the property work with PropertyGrid you need add the Attribute
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
on your property definition.
This attribute tells Serializer this property needs further action to
serialize.
For more information, you may read the follow link in MSDN:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemComponentModelDesignerSerializationVisibilityAttributeClassTopic.
asp

Does this answer solve your problem?
Please be free to let me know if you still have problem on it.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "Norm Dotti" <[email protected]>
| Sender: "Norm Dotti" <[email protected]>
| Subject: Databinding question
| Date: Tue, 21 Oct 2003 13:57:56 -0700
| Lines: 52
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOYFgDqmlHvhUlaTMuAqVAhvyUrUw==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54963
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a user control that I drop to windows forms. I also
| have typed dataset that is defined in the windows form
| project. I want to bind the textboxes within the
| usercontrol to a datatable field in this typed dataset.
| I found the following old posting on this issue. But what
| happens is, this property is not written to codebehind of
| the form if it's set. So when I run the program it clears
| the binding info. What do I have to do to make this work?
|
| /*
| Hello Colin,
|
| You can export the DataBindings property of the child
| control via property.
| Since the DataBindings property is read only, you may need
| to write some
| code to handle set method of the property. This is a
| sample code:
|
| public System.Windows.Forms.ControlBindingsCollection
| textBindings
| {
| set
| {
| System.Windows.Forms.ControlBindingsCollection bindings;
| bindings =
| (System.Windows.Forms.ControlBindingsCollection)value;
| textBox1.DataBindings.Clear();
| foreach(Binding b in bindings)
| textBox1.DataBindings.Add(b);
| }
| get
| {
| return textBox1.DataBindings;
| }
| }
|
| Hope it helps.
|
| Best regards,
|
| Lion Shi, MCSE, MCSD
| Microsoft Support Engineer
|
| This posting is provided "AS IS" with no warranties, and
| confers no rights.
| You assume all risk for your use. 2001 Microsoft
| Corporation. All rights
| reserved.
| */
|
| Thanks
|
 
Back
Top