Bind a property to a TextBox

dubem1

Newcomer
Joined
Dec 5, 2002
Messages
20
Hello!

I want to bind the properties of a class directly
to controls in a winform. I know it can be done in VB.net but I just don't know how. Can someone helps and/or provide an example please

Thanks a lot!!!!

Martin
 
Binding as far as i know it refers to the binding of data from a database onto a control.
In laymans terms... when you change records all the textboxes and labels generate text automatically from the database (only if you bind all the controls first)

As far as accomplishing what you wish to do...
you could inherit from the UserContrl class.
you do not want to just type this in below the class declaration!!!!

go to Project on the menu
click Add User Control

Your new control will contain properties of a regular control plus whatever you add...

To display these properties during design time when the form is drawn you should use the system.component.componentmodel namespace (the syntax for this is strange i can send an example if you wish) Add it before the delclaratoin of a property

i hope that helps
 
You can virtually bind to almost any object in .Net, not just from a database. You can try the following:
If you got a class like this
Visual Basic:
Public Class myBoundToClass

    Private _SomeData As String = "DefaultValue"

    Public Property SomeData() As String
        Get
            Return _SomeData
        End Get
        Set(ByVal Value As String)
            _SomeData = Value
        End Set
    End Property
End Class
and you've got a textbox on a form, you can bind the textbox to the class above by adding the following code in the, e.g. form load event:
Visual Basic:
TextBox1.DataBindings.Add("Text", _myBoundClass, "SomeData")
where _myBoundClass refers to a instance of the above class.
Hope it helps
Cheers!
 
hey wow that's cool i might have to use that
Let me get this right... so if i have a property in one class and i want to have another property in another class mirror that property this would be what to do eh?
How would I define DataBinding property in a class that is already using inheritence?
 
Databinding only available on a class that inherited from Control

msdn:
Binding Class:
Represents the simple binding between the property value of an object and the property value of a control.

Check out documentation on the Binding Class for more info...
 
Back
Top