Dynamic WinForms Label & Textboxes

G

Guest

I have a WinForms app, with each forms having many Text-boxes that bind to a
DataTable.

Associate with each Textbox would be a (text) label. Is there any simple
way such that I can "bind" the Text labels to the TextBoxes, so I can
dynamically set each Label.Text property rather than having to hard-wire the
Label.Text for each Label for textbox?
 
A

Alex Meleta

Hi Patrick,

You can create a custom control to combine in it other controls.

Regards, Alex
[TechBlog] http://devkids.blogspot.com



P> I have a WinForms app, with each forms having many Text-boxes that
P> bind to a DataTable.
P>
P> Associate with each Textbox would be a (text) label. Is there any
P> simple way such that I can "bind" the Text labels to the TextBoxes,
P> so I can dynamically set each Label.Text property rather than having
P> to hard-wire the Label.Text for each Label for textbox?
P>
 
G

Guest

Can you elaborate a little bit more?

I have
1) created a .Net 2TestCustomControl in VS2005
2) Dragged a Label into the Component designer
3) Dragged a Textbox into the Component designer

What I want is to be able to do something like
MyTestControl.DataBinding.Add("Text",myDataTable["myTable"],"myField");

And for the CustomControls Label.Text and TextBox.DataBindings to be updated
automatically.

What code do I have to write within the Custom Control to achieve this?
 
A

Alex Meleta

Hi Patrick,

If you override Text propery of user control (or create another property)
you can put the code to update other controls. Or create two properties for
both databindings.

P> And for the CustomControls Label.Text and TextBox.DataBindings to be
P> updated automatically.
But, do you want to update other bindings by setting only one?

Regards, Alex
[TechBlog] http://devkids.blogspot.com



P> Can you elaborate a little bit more?
P>
P> I have
P> 1) created a .Net 2TestCustomControl in VS2005
P> 2) Dragged a Label into the Component designer
P> 3) Dragged a Textbox into the Component designer
P> What I want is to be able to do something like
P> MyTestControl.DataBinding.Add("Text",myDataTable["myTable"],"myField"
P> );
P> And for the CustomControls Label.Text and TextBox.DataBindings to be
P> updated automatically.
P>
P> What code do I have to write within the Custom Control to achieve
P> this?
P>
P> "Alex Meleta" wrote:
P>
Hi Patrick,

You can create a custom control to combine in it other controls.

Regards, Alex
[TechBlog] http://devkids.blogspot.com
P> I have a WinForms app, with each forms having many Text-boxes that
P> bind to a DataTable.
P>
P> Associate with each Textbox would be a (text) label. Is there any
P> simple way such that I can "bind" the Text labels to the
TextBoxes,
P> so I can dynamically set each Label.Text property rather than
having
P> to hard-wire the Label.Text for each Label for textbox?
P>
 
G

Guest

Where (within the CustomControl) should code to wire up base on the Custom
Property for the Label.Text and TextBox.DataBindings be inserted?

Alex Meleta said:
Hi Patrick,

If you override Text propery of user control (or create another property)
you can put the code to update other controls. Or create two properties for
both databindings.

P> And for the CustomControls Label.Text and TextBox.DataBindings to be
P> updated automatically.
But, do you want to update other bindings by setting only one?

Regards, Alex
[TechBlog] http://devkids.blogspot.com



P> Can you elaborate a little bit more?
P>
P> I have
P> 1) created a .Net 2TestCustomControl in VS2005
P> 2) Dragged a Label into the Component designer
P> 3) Dragged a Textbox into the Component designer
P> What I want is to be able to do something like
P> MyTestControl.DataBinding.Add("Text",myDataTable["myTable"],"myField"
P> );
P> And for the CustomControls Label.Text and TextBox.DataBindings to be
P> updated automatically.
P>
P> What code do I have to write within the Custom Control to achieve
P> this?
P>
P> "Alex Meleta" wrote:
P>
Hi Patrick,

You can create a custom control to combine in it other controls.

Regards, Alex
[TechBlog] http://devkids.blogspot.com
P> I have a WinForms app, with each forms having many Text-boxes that
P> bind to a DataTable.
P>
P> Associate with each Textbox would be a (text) label. Is there any
P> simple way such that I can "bind" the Text labels to the
TextBoxes,
P> so I can dynamically set each Label.Text property rather than
having
P> to hard-wire the Label.Text for each Label for textbox?
P>
 
A

Alex Meleta

Hi Patrick,

Anywhere add something like.. this (as example):

public void ApplyBinding(DataSet dataSet)
{
DataBindings.Add("TextBox", dataSet, "Table1.Column1");
DataBindings.Add("TextLabel", dataSet, "Table1.Column2");
}, where TextBox and TextLabel are properties onto edit box and label.

Certain example depends on real needs.

Regards, Alex
[TechBlog] http://devkids.blogspot.com


Where (within the CustomControl) should code to wire up base on the
Custom Property for the Label.Text and TextBox.DataBindings be
inserted?

Alex Meleta said:
Hi Patrick,

If you override Text propery of user control (or create another
property) you can put the code to update other controls. Or create
two properties for both databindings.

P> And for the CustomControls Label.Text and TextBox.DataBindings to
be
P> updated automatically.
But, do you want to update other bindings by setting only one?
Regards, Alex
[TechBlog] http://devkids.blogspot.com
P> Can you elaborate a little bit more?
P>
P> I have
P> 1) created a .Net 2TestCustomControl in VS2005
P> 2) Dragged a Label into the Component designer
P> 3) Dragged a Textbox into the Component designer
P> What I want is to be able to do something like
P>
MyTestControl.DataBinding.Add("Text",myDataTable["myTable"],"myField"
P> );
P> And for the CustomControls Label.Text and TextBox.DataBindings to
be
P> updated automatically.
P>
P> What code do I have to write within the Custom Control to achieve
P> this?
P>
P> "Alex Meleta" wrote:
P>
Hi Patrick,

You can create a custom control to combine in it other controls.

Regards, Alex
[TechBlog] http://devkids.blogspot.com
P> I have a WinForms app, with each forms having many Text-boxes
that
P> bind to a DataTable.
P>
P> Associate with each Textbox would be a (text) label. Is there
any
P> simple way such that I can "bind" the Text labels to the
TextBoxes,
P> so I can dynamically set each Label.Text property rather than
having
P> to hard-wire the Label.Text for each Label for textbox?
P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top