Tab Control - disable button when switching tabs.

Hi,

I have created a windows form with a tab control.  Each tab control has a number of textboxes which are filled with data using databind.  I have an "Apply" button which is disabled until any of the text is changed in the textboxes (using the .TextChanged handler).  The problem is that when I click another tab the TextChanged handler is executed and the "Apply" button is enabled even though no text has been changed (see code example below).  

Private Sub TextBox_Changed(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbCompanyName.TextChanged
    Me.btnApply.Enabled = True
End Sub

Anybody any ideas how to keep the apply button disabled if nothing was changed on the first tab?

Thanks

Marcus
marcus_dAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stripathiCommented:
Marcus,

You may want to move this code to the lostfocus event which will only happen if user enters the box and leaves it. This may solve this changed event issues as this will be fired even if you have any databinding code in TabChanged event. So when you click on a tab, that code will make Changed event to trigger with effect of enabling btnApply to enable.

Sal.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marcus_dAuthor Commented:
Thanks for your response.  I've taken your advice and used the lostfocus handler to enable the apply button.  Because I only wanted the apply button to be enabled if text had been changed I used the following procedure :-

Private Sub CompanyName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbCompanyName.LostFocus
   If Me.tbCompanyName.Text <> strCompanyName Then
      Me.btnApply.Enabled = True
   End If
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.