0

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

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.

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

How to disable? You cannot disable them. You can only go through SelectedIndexChanged event of the dropDownList, and get selected index. And if index is between 120 and 150, do not use this item.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.