Binding a Text Box

D

David Miller

Help,

I give up... I have a class that I created.

In the Load call of a custom control I bind a text box to the class that I
created.
The code for that part is: TxtLast.DataBindings.Add(New Binding("Text",
CurrentRecord, "LastName"))

If I change the value of the class in the Load call the text box that it
bound to updates with the new value. So if within the Load Proc of the
control there is a line that says CurrentRecord.Lastname = "Smith" the text
box will display "Smith".

But, if I change the value in any other procedure within that control the
textbox does not update it's value. What am I doing wrong?

Thanks,
David
 
B

Bart Mermuys

Hi,

David Miller said:
Help,

I give up... I have a class that I created.

In the Load call of a custom control I bind a text box to the class that I
created.
The code for that part is: TxtLast.DataBindings.Add(New Binding("Text",
CurrentRecord, "LastName"))

If I change the value of the class in the Load call the text box that it
bound to updates with the new value. So if within the Load Proc of the
control there is a line that says CurrentRecord.Lastname = "Smith" the
text box will display "Smith".

But, if I change the value in any other procedure within that control the
textbox does not update it's value. What am I doing wrong?

If you are using NET1.1 then add an event (typeof EventHandler) for each
property and name it "propertyname"+Changed, eg:

Public Class Class1
Private _LastName As String

Public Event LastNameChanged As EventHandler
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
If (value <> _LastName) Then
_LastName = value
RaiseEvent LastNameChanged(Me, EventArgs.Empty)
End If
End Set
End Property

End Class

This should work in NET2.0 too, but in NET2.0 i would implement the new
INotifiyPropertyChanged instead on your class.

HTH,
Greetings
 

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