Binding textboxes inside a Usercontrol

I'm using Visual Studio 2010, C#, a Windows Form application.

I created some user controls with textboxes that will be repeated in several forms.

It works fine however, I need to binding them to a bindingSource in the form in which I place them.
Well, I can't. I marked the controls as Modifier = Public, but, there's no physical way to "Select" an individual textbox to change the binding properties.

How do I do that?

I guess it has to be by code.
What's the proper way to do this?






LVL 1
fischermxAsked:
Who is Participating?
 
käµfm³d 👽Commented:
You can expose the TextBox by adding a property to your UserControl, as demonstrated below. Alternatively, you can expose only the members you are interested in instead of the entire TextBox.
public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }

    // Expose TextBox to outside world
    public TextBox YourTextBox { get { return this.textBox1; } }
}

Open in new window

0
 
fischermxAuthor Commented:
Thank you!, that worked...

A side question on the topic, how do I make these properties to be grouped together in the Properties window?

I know there's a tag for Categories that works when one choose that ordering.

But there's also a way when a property is marked with a tiny horizontal arrow point, like the Font property, then it display a lot of properties inside.
How do I do that?
0
 
käµfm³d 👽Commented:
That is a whole other topic that I'm afraid I don't have much experience with. I can, hopefully, point you in the right direction. See:

0
 
fischermxAuthor Commented:
Thank you!!
0
 
käµfm³d 👽Commented:
NP. Glad to help  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.