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 / Design Time / April 2004

Tip: Looking for answers? Try searching our database.

Binding to nested controls using property grid in design mode does not work? (2nd)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arthur - 02 Apr 2004 19:15 GMT
Hi everybody,

I have a problem which I don't fully understand yet. I'll try to describe a
simplified model:

I have a Windows form "Form1". It contains some data-source-type object like
"DataSet1".

Then I have a UserControl control "UserControl1" that contains a TextBox
control "textBox1". This controls is exposed for simplicity as a public
property "NestedTextBox" of the "UserControl1" like this:

public TextBox NestedTextBox
{
   get { return textBox1; }
}

The "UserControl1" is sited on "Form1" as "userControl11".

In design mode, when I select the "userControl11" on the "Form1" and then I
select its "Tag" property under "(DataBindings)" in the property grid, a
drop-down list opens and it shows the "DataSet1" item.

However, when I select in the property grid the "NestedTextBox" property of
the "userControl1" and then I select the "Tag" or "Text" property under
"(DataBindings)", then the drop-down list opens but it is empty!

I've spent this week reading MSDN stuff and doing a lot of experiments, but
I've probably missed something.

I've understood that using attributes and designers and type converters and
type editors I can implement almost anything, but it seems to me that it
would be overkill implementing all that customization code. I simply need to
promote the "DataSource1" from the "Form1" to the "userControl1" (or
"textBox1"?). I would expect that it should be enough to use the correct
attribute and type converter, but I'm not able to find out which ones the
"Form1" actually uses.

Can anybody help with this? Thank you a lot in advance.

Arthur
Daniel Carlsson - 05 Apr 2004 16:06 GMT
I cant remember all the details, but in your case you want to set a property
on a control that is not added to the design surface, this is because its
contained (and pretty much hidden) by your UserControl.

You can solve this in two ways AFAIK.
The easiest is that instead of exposing the TextBox you create a property in
the UserControl that exposes the property of the TextBox. Ie, InnerTag which
simply uses the TextBox's Tag as the datastore. Tag that as <DataBindable>
and it *should* work. I didnt test it though so I might have forgotten some
detail..

The other way to solve it would be to read the following article which
teaches you how to create a container control, its a bit overkill the way he
does it as he provides a way to add controls (a colored box in the example)
but I think you can use a subset of the code to get it to work in your case.
Point being, you need to add your textbox as a control to the designsurface
to be able to bind it properly to the dataset.
http://www.divil.co.uk/net/articles/designers/collectioncontrols.asp

Id recomend the first version in this case, but the tutorial is a good read
anyways
Hope it helps
/Dan

> Hi everybody,
>
[quoted text clipped - 37 lines]
>
> Arthur
Arthur - 06 Apr 2004 08:27 GMT
Thank you, Dan, for your answer. I'll definitely go through the article
you've pointed to because it seems to be very interesting.

In the meantime I've completed a lot of experiments and it seems that there
is no one-step way to go.
The simplest solution I've found till now is like this:

1) I need a custom converter class that derives from the ComponentConverter:

public class MyConverter :  System.ComponentModel.ComponentConverter
{
   public override bool CanConvertTo(...)
   {
       // return true for the MyType destination type
   }
   public override object ConvertTo(...)
   {
       // return an empty string for the String destination type and value
of the MyType type
   }
}

2) I need a custom type class that exposes the DataBindings collection and
is maintained by the converter. The DataBindings property shold be
persistent.

[TypeConverter(typeof(MyConvereter))]
public class MyType
{

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   public ControlBindingsCollection DataBindings
       {
           get {return innerTextBox.DataBindings;
       }
}

3) The parent user control should exposes a property of the MyType type. It
should be also persistent.

public class MyControl : System.Windows.Forms.UserControl
{
   private MyType myProperty;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   public MyType MyProperty
   {
       get {return myProperty;}
   }
}

Maybe this can be helpful also for others.
Arthur

> I cant remember all the details, but in your case you want to set a property
> on a control that is not added to the design surface, this is because its
[quoted text clipped - 68 lines]
> >
> > Arthur

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.