469,645 Members | 1,174 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Disable ListItem in Drop Down List

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.
Aug 28 '07 #1
4 2476
Just remove the unwanted items from the list, then users can't select them.

"KerryC" <Ke****@discussions.microsoft.comwrote in message
news:3A**********************************@microsof t.com...
>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.

Aug 28 '07 #2
Obviously that would be nice but I need to keep them in there!

"schneider" wrote:
Just remove the unwanted items from the list, then users can't select them.

"KerryC" <Ke****@discussions.microsoft.comwrote in message
news:3A**********************************@microsof t.com...
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.


Aug 28 '07 #3
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)
Aug 28 '07 #4
Possible use the Validation events, Causes Validation property?
"Matt F" <mf****************@nospam.nospamwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl...
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)


Aug 28 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by MEM | last post: by
2 posts views Thread by Yoshitha | last post: by
1 post views Thread by Dante | last post: by
1 post views Thread by Ami Schreiber | last post: by
5 posts views Thread by Mark Rae | last post: by
kestrel
reply views Thread by kestrel | last post: by
4 posts views Thread by TycoonUK | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.