Disable ListItem in Drop Down List

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?S2VycnlD?=

    #1

    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 onselectedindex change.

    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.
  • schneider

    #2
    Re: Disable ListItem in Drop Down List

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

    "KerryC" <KerryC@discuss ions.microsoft. comwrote in message
    news:3A96E166-1E23-4502-8EC4-ED885FEE351F@mi crosoft.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 onselectedindex change.
    >
    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.

    Comment

    • =?Utf-8?B?S2VycnlD?=

      #3
      Re: Disable ListItem in Drop Down List

      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" <KerryC@discuss ions.microsoft. comwrote in message
      news:3A96E166-1E23-4502-8EC4-ED885FEE351F@mi crosoft.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 onselectedindex change.

      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.
      >
      >
      >

      Comment

      • Matt F

        #4
        Re: Disable ListItem in Drop Down List

        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_Selec tedIndexChanged (ByVal sender As System.Object,
        ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged

        If ComboBox1.Selec tedItem.ToStrin g() = "Item 2" Then
        ComboBox1.Selec tedIndex += 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)


        Comment

        • schneider

          #5
          Re: Disable ListItem in Drop Down List

          Possible use the Validation events, Causes Validation property?


          "Matt F" <mfielderREMOVE CAPS@nospam.nos pamwrote in message
          news:ehBR3Aa6HH A.5136@TK2MSFTN GP02.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_Selec tedIndexChanged (ByVal sender As System.Object,
          ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
          >
          If ComboBox1.Selec tedItem.ToStrin g() = "Item 2" Then
          ComboBox1.Selec tedIndex += 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)
          >
          >

          Comment

          Working...