We help IT Professionals succeed at work.
Get Started

Disable multiple items from DropDownList. Someone need to check code!

dejandejanovic
on
467 Views
Last Modified: 2012-08-14
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

Open in new window


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

Open in new window


My goal is if I would have a 365 items in DropwDownList to disable items for example between 120 and 150.

Thank you in advance for help to anyone.
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE