Groups | Blog | Home
all groups > dotnet windows forms > august 2007 >

dotnet windows forms : Dynamic WinForms Label & Textboxes


Patrick
8/31/2007 6:36:07 AM
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
Patrick
8/31/2007 7:16:02 AM
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?

[quoted text, click to view]
Patrick
8/31/2007 9:24:02 AM
Where (within the CustomControl) should code to wire up base on the Custom
Property for the Label.Text and TextBox.DataBindings be inserted?

[quoted text, click to view]
Alex Meleta
8/31/2007 1:52:46 PM
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>

Alex Meleta
8/31/2007 3:11:14 PM
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>
[quoted text, click to view]

Alex Meleta
8/31/2007 6:27:30 PM
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



[quoted text, click to view]

AddThis Social Bookmark Button