Cannot bind a ConnectionStringBuilder instance to a custom control

Cannot bind a ConnectionStringBuilder instance to a custom control

Post by TGlsaWF » Thu, 17 Jan 2008 15:29:00


Hi,

First the context :
VS2K8
2 .NET 2.0 projects (the control project and the WinForm test project)
The control is supposed to help someone build a connection string

What I intend to do :
Bind the custom control's controls (textbox, combobox, ...) to a
ConnectionStringBuilder instance members (the instance is a private member of
the custom control).

Where is the binding done :
I tried it in the custom control constructor and in the "load" method.

What I get :
An error message telling me that it can't be bound (ArgumentException raised
on DataMember).

What I tried then :
Debug to see if my instance is not null, if the member (ie "Password") is
not mistyped, if the member is not null ... Everything seems to work.

Any idea ?
 
 
 

Cannot bind a ConnectionStringBuilder instance to a custom control

Post by Morten Wen » Fri, 18 Jan 2008 02:47:11

Hi Lilian,

The binding should take place somewhere you have a reference to both the control and the binding source. This typically happens in some kind of parent control, which in your case would be something like the main user control setting up databinding for all its members.

Setting up Databinding in the constructor may not be such a good idea because some controls are not properly initialized at that time. If you pass the binding object to the constructor, store the reference and set up the binding in the Load event.






--
Happy coding!
Morten Wennevik [C# MVP]