954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

disable textbox when dropdown selected

hi,

I am trying to learn winforms, the dropdown is taking its value from database. i want to disable the textbox when the selection is first option, but if it is second i want to enable the textbox..

how would i do this ?

thanks

sam1
Posting Whiz
300 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

On the SelectedIndexChanged event of the combobox add your code as (Where 'A', 'B' and 'C' are the items in your dropdown)

If ComboBox1.Text = "A" Then
ComboBox1.Enabled = False
ElseIf ComboBox1.Text = "B" Then
ComboBox1.Enabled = True
ElseIf ComboBox1.Text = "C" Then
ComboBox1.Enabled = True
End If

Regards
:)

MukeshZ
Newbie Poster
17 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

thanks for the reply, but i was wondering is there another way like maybe using the index(0) of the value to disable the textbox

sam1
Posting Whiz
300 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

Hi,

Try this condition :

If Combo1.SelectedIndex = 0 Then
    ' Code to disable
Else
    ' Code to Enable
End If


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

veena answered it. but you also can do with selected item :

If Combo1.SelectedItem = "What" Then
    Textbox1.Enable = False
Else
    Textbox1.Enable = True
End If
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You