Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi there.

I try to enable a textbox "Textbox2" after the "Textbox1" is no more empty.

My code is that

If TextBox1.Text = "" Then
TextBox2.Enabled = False
Else
TextBox2.Enabled = True
End If

But when i type something inside the Textbox1 the Textbox2 does not enable

[EDIT - OP comment moved from solution]
Event is
VB
Private Sub Form1_Load(sender As Object, e As EventArgs)

Inside a TabPage
Posted
Updated 15-Jul-14 3:02am
v2
Comments
Thanks7872 15-Jul-14 3:26am    
Tag question properly.
CHill60 15-Jul-14 9:03am    
Don't use solutions to make comments - use the "Reply" or "Have a Question or Comment?" link next to a post. I have deleted your non-solutions and moved the relevant information into your Question using the "Improve Question" link

In which event are you doing this. you need do this key down event.
 
Share this answer
 
Because you have this code in the Form_Load event you are only setting the initial state of the TextBox2

You also need to respond to the user entering data into TextBox1

You could put this into the Private Sub TextBox1_KeyDown event, but note that it would run each time the user pressed a key.

My preference is to act on the contents of TextBox1 only when we are sure that the User has finished whatever they are doing in that control - The TextBox_Validated event is handy for that...
VB
Private Sub TextBox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
    If Me.TextBox1.Text.Length > 0 Then
        Me.TextBox2.Enabled = True
    Else
        Me.TextBox2.Enabled = False
    End If
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900