enable button based on textboxes

david_reinjal

Member
Joined
Jun 24, 2006
Messages
8
Programming Experience
Beginner
hi guys,
i have menustrip which has menus such as File, Edit, Tools, etc. I also have 2 textboxes. Initially I am keeping the Menus disabled. I need to enable the menu only when i enter the path in textbox. how do i do that?
Thanks
 
You'd handle the TextChanged event of the TextBox and test the Text property, then enable or disable your menu items accordingly. What you test for depends on what you want to allow. You may just test that it is not empty or you may test that it is a valid file path. That's up to you.
 
yes i need to check whether the path in textbox is not empty and should be a valid path. the path that i m giving is where my database is stored. i m throwing an exception if the path in the textbox is not correct but i need to enable the menustrip if the path in the textbox is correct.
 
In which case i would use the onvalidating event. In there test the value of the text if it's not what you want you can cancel the event and display a messagebox or something.
 
in the textbox's TextChanged event simply check to see if the text entered is a valid path or not:

VB.NET:
Private Sub Textbox1_TextChanged (...) Handles Textbox1.TextChanged
  If System.IO.Directory.Exists(Textbox1.Text) = True Then
    'Enable Menu
  Else
    'Disable Menu
  End If
End Sub
 
Back
Top