Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

i'm not lazy i'm just resting before i get tired.
Posted

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

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:

TextBox1.DataBindings.Add("Text", _myBoundClass, "SomeData")

where _myBoundClass refers to a instance of the above class.

Hope it helps

Cheers!

Howzit??
Posted

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?

i'm not lazy i'm just resting before i get tired.
Posted

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...

Howzit??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...