Anything Changed Flag

  • Thread starter Thread starter Not Aaron
  • Start date Start date
N

Not Aaron

I am wondering if there is an event or control that would throw a flag
once any kind of textbox or control on the form had changed. Sort of
like with Word say, if you bring up a document, and don't do any
editing, it doesn't ask you to save. I am wanting that same effect
without having to set my own flag and goto every controls textchanged,
etc to set it myself.

thanks in advance
 
Not Aaron said:
I am wondering if there is an event or control that would throw a flag
once any kind of textbox or control on the form had changed. Sort of
like with Word say, if you bring up a document, and don't do any
editing, it doesn't ask you to save. I am wanting that same effect
without having to set my own flag and goto every controls textchanged,
etc to set it myself.

thanks in advance

It's like a lot of thing in .NET: You'll have to do it yourself, but it's
ridiculously easy to do.

Private changed = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


For Each c As Control In Controls
If TypeOf c Is TextBox Then
AddHandler c.TextChanged, AddressOf ChangeListener
ElseIf TypeOf c Is RadioButton Then
AddHandler DirectCast(c, RadioButton).CheckedChanged, AddressOf
ChangeListener
'etc for the control types you use. . .
End If

Next

End Sub


Private Sub ChangeListener(ByVal sender As Object, ByVal e As
System.EventArgs)
changed = True
End Sub

David
 
Loop through the controls on the form. If the control is a textbox then add
a handler to the textchanged event

Dim ctl As Control
For Each ctl In Form.Controls
If TypeOf ctl Is TextBox then
AddHandler ct1, Address HandlerForAllTextBox_ChangedEvent
End If
Next

Hope this helps.

Chris
 
Thanks for the help, its what I was looking for. I ended up making a
function that passes in a control. Therefore, when I do the typeOf, I
check for a groupbox/panel/etc and then have it call itself to make
sure I cover all controls. Thanks again.

- Not Aaron...really
 

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

Back
Top