Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bind a text box to a custom class property

Status
Not open for further replies.

butler

MIS
Oct 12, 1998
88
US
Greetings,

Is there a way to bind a text box to property in a class. This is what I tried but it didn't work:

txtName.DataField = clsCustomer.Name

I would like this to work so that when clsCustomer.Name changes the text box is automatically updated, and when txtName.text changes then clsCustomer.Name is automatically updated...

Thanks,
--bill
 
As for changing the textbox when the class is updated you can do this 3 ways, but one of them breaks proper programming practice.

1: The class changes the text in the box directly. This is not good because it breaks the "self contained" programming practice of a class ( it should not refer to an outside object directly through code ).

2: Put an event inside the class, and declare it useing Withevents in your main program. It can then raise an event, and the textbox text can be updated inside this event.

3: Have a property in the class that is assigned the control you want to update. Then, inside the class itself, you update this control.

Example:
Private m_TextBx as TextBox

Property Set TextBx( ByRef MyBox As TextBox)
Set m_TextBx = MyBox
End Property

And then when you change the class property clsCustomer.Name

Property Let Name( NewName As String )
' other code here to do whatever you want in this proceedure. validate the new entry, etc.

m_TextBx.Text = NewName
End Property


For changing the class property when the text box changes, then you would trigger this from the text box change event.

Make sure that you put some sort of code in there that will keep you from getting caught in a loop. ( i.e. Text change fires the class change that fires the text change and so on and so on... )

Hope this helps,

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top