Check for Changes

  • Thread starter Thread starter Michael Turner
  • Start date Start date
M

Michael Turner

Hi

I have a form with multiple text fields and need a way of checking to see if
changes are made in any of them I know I could use the keypress on each box
but there must be an easier way.

Thanks in advance.

Mike.
 
I see what you mean but I was hoping for a more global command that would
allow me to say if anything was modified on the form then it would run
rather than add code to each textbox.

Mike.
 
I have a form with multiple text fields and need a way of checking to see if
changes are made in any of them I know I could use the keypress on each box
but there must be an easier way.

Have a look at the TextChanged event.

Cheers

Blu
 
* "Michael Turner said:
I have a form with multiple text fields and need a way of checking to see if
changes are made in any of them I know I could use the keypress on each box
but there must be an easier way.

Loop through the textboxes and add a handler to their 'ModifiedChanged'
event.
 
Hi,

Here is how you can check all the controls on the form.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

CheckIfDirty(Me.Controls)

End Sub

Private Sub CheckIfDirty(ByVal ctrls As Control.ControlCollection)

For Each ctrl As Control In ctrls

If TypeOf ctrl Is TextBox Then

If DirectCast(ctrl, TextBox).Modified Then

Dim strOut As String

strOut = String.Format("{0} is dirty", DirectCast(ctrl, TextBox).Name)

Trace.WriteLine(strOut)

End If

End If

'

' check child controls if any

'

CheckIfDirty(ctrl.Controls)

Next

End Sub



Ken
 
Back
Top