Jess31
asked on
Variable Event ?
Using vb.net and winforms.
In the code behind the Form - how can I set an event on a local variable that will trigger anytime the variable changes value?
In the code behind the Form - how can I set an event on a local variable that will trigger anytime the variable changes value?
You can't for a variable. It doesn't work that way.
Use a class:
and in your form/module:
Public Class MyVariable
Public Event Changed()
Private _Data As String
Property Data As String
Get
Data = _Data
End Get
Set(value As String)
_Data = value
RaiseEvent Changed()
End Set
End Property
End Class
and in your form/module:
Private WithEvents testVar As New MyVariable
Private Sub varChanged() Handles testVar.Changed
'do your thing here
MessageBox.Show("You variable has changed")
End Sub
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
testVar.Data = "testdata"
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.