Disable ListItem in Drop Down List

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to disable a list item in a drop down list.

The list looks something like

"Item 1

Other items that may interest you

Item 2
Item 3"

So items with an index of 1, 2 and 3 should not be selectable as I do not
want them to fire the onselectedindexchange.

I know that there is an enabled property but that this does not apply to
dropdownlists.

Does anyone know of another way I can disable these items?

Thanks for your help.
 
I'm not aware of any way to do this in the way that you want. The only way
I can think of to do something like this is to handle it manually.

For instance if you don't want to allow "Item 2" to be selected, you could
use something like:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

If ComboBox1.SelectedItem.ToString() = "Item 2" Then
ComboBox1.SelectedIndex += 1

End Sub

Of course, this has a couple of problems such as incrementing past the last
item, etc. What you would have to do is keep track of the current value of
ComboBox - then depending on whether you allow the change, update the
manually tracked value and allow the change or manually set the combo box
back to the value stored previously.



HTH (as hokey as it is)
 
Back
Top