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.
 
Write a single function that handles TextChanged Event for all textboxes. So that will run whenever any textbox is changed and focus is shifted to the next control.

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
 
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
 

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