Disable multiple items from DropDownList. Someone need to check code!
Hello,
I would like to disable a specific items from DropDownList. I have below code but it does not working. So, need someone to told me what I'm doing wrong. DropDownList have 5 items.
And, I'm getting error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Dim X As Integer = 0 <> 1 DropDownList1.Items(X).Enabled = False End Sub
But, if I add a different value for X, then it disable 1st and 2nd item.
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Dim X As Integer = 0 or 1 DropDownList1.Items(X).Enabled = False End Sub
I have found a solution for me.
Dim X as integer
For x = 0 to 4
If DropDownList1.item(x).text.Contains("May") then
msgbox("yes")
else
msgbox("no")
next
Dim X as integer
For x = 0 to 4
If DropDownList1.item(x).text
msgbox("yes")
else
msgbox("no")
next
So, maybe this will help also to other users.