Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Disabling individual options in an UltraOptionSet

Disabling individual options in an UltraOptionSet

New Discussion
Matrikon
Matrikon asked on May 12, 2011 4:33 AM

I’ve got a radio group using an UltraOptionSet that I would like to disable certain options in at different times.

I’ve tried looking for options on the set itself, but can only find the global enabled or disabled property.

The individual OptionSetItem objects don’t seem to have an enabled property…

Does anyone know how this can be done?

Thanks

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Jan 15, 2008 2:27 PM

    Hi,

    No, there’s is currently no way to disable items in the OptionSet. The only thing you could do is remove the item from the list so the user can’t select it.

     

     

    • 0
      Ivo Huizinga
      Ivo Huizinga answered on Jul 15, 2008 3:09 PM

      I found a way: 

      Dim element As Infragistics.Win.OptionSetOptionButtonUIElement

      element = DirectCast(UltraOptionSet1.UIElement.ChildElements(0).ChildElements(xxx), Infragistics.Win.OptionSetOptionButtonUIElement)

      With element
          .Enabled = False
          .Invalidate()
      End With

      Change xxx for the index of the ValueListItem you want to disable. Item still clickable though 🙁

      • 0
        Randall
        Randall answered on May 13, 2009 4:20 PM

        When I try the following code in C#

        Infragistics.Win.OptionSetOptionButtonUIElement element = default(Infragistics.Win.OptionSetOptionButtonUIElement);
            
        element = (Infragistics.Win.OptionSetOptionButtonUIElement)UltraOptionSet1.UIElement.ChildElements[0].ChildElements[xxx];
        {
                 element.Enabled = false;
                 element.Invalidate();
        }

        There are never any elements in ChildElements above, even though I have 4 items in the "UltraOptionSet1".  Any Ideas?

      • 0
        Matt Snyder
        Matt Snyder answered on May 13, 2009 6:07 PM

        When are you trying to execute this code?  You would likely need to do this in a CreationFilter because the elements could be repositioned several times throughout the course of the application, and doing this in AfterCreateChildElements will ensure that you actually do have elements to work with.

        -Matt

      • 0
        tomas
        tomas answered on Sep 30, 2009 4:01 PM

        -Matt

        Please could put an example code to solve the above problem.

        Thanks

    • 0
      Nurit
      Nurit answered on Jan 4, 2011 7:24 AM

      Is such an option available in infragistics 10.3 ?

      Thanks.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jan 4, 2011 10:20 PM

        No, there is no way to disable individual items.

      • 0
        Tony Tullemans
        Tony Tullemans answered on May 12, 2011 4:33 AM

        Never say never…

        1. Create a module with these functions:

          <Extension()> _
          Public Function GetIndex(ByVal items As ValueListItemsCollection, ByVal dataValue As Object) As Integer
            Dim result As Integer = -1
            Try
              If dataValue IsNot Nothing Then
                Dim i As Integer = 0
                For Each item As Infragistics.Win.ValueListItem In items
                  If item.DataValue IsNot Nothing AndAlso dataValue.ToString.Equals(CStr(item.DataValue)) Then
                    result = i
                    Exit For
                  End If
                  i += 1
                Next
              End If
            Catch ex As Exception
              Throw New Exception(String.Format("{0}.GetIndex Error", items.GetType.Name), ex)
            End Try
            Return result
          End Function
          <Extension()> _
          Public Function GetItem(ByVal items As ValueListItemsCollection, ByVal dataValue As Object) As ValueListItem
            Dim result As ValueListItem = Nothing
            Try
              If dataValue IsNot Nothing Then
                For Each item As Infragistics.Win.ValueListItem In items
                  If item.DataValue IsNot Nothing AndAlso dataValue.ToString.Equals(CStr(item.DataValue)) Then
                    result = item
                    Exit For
                  End If
                Next
              End If
            Catch ex As Exception
              Throw New Exception(String.Format("{0}.GetItem Error", items.GetType.Name), ex)
            End Try
            Return result
          End Function
          <Extension()> _
          Public Function GetUIItem(ByVal ctrl As Infragistics.Win.UltraWinEditors.UltraOptionSet, _
                                    ByVal dataValue As Object) As OptionSetOptionButtonUIElement
            Dim result As OptionSetOptionButtonUIElement = Nothing
            Try
              If dataValue Is Nothing Then Throw New ArgumentNullException("The data value may not be null")
              Dim item As ValueListItem = ctrl.Items.GetItem(dataValue)
              If item IsNot Nothing Then
                For Each childElement As UIElement In ctrl.UIElement.ChildElements
                  If TypeOf childElement Is OptionSetEmbeddableUIElement Then
                    Dim embeddableElement As OptionSetEmbeddableUIElement = CType(childElement, _
                                             OptionSetEmbeddableUIElement)
                    For Each subElement As UIElement In embeddableElement.ChildElements
                      If TypeOf subElement Is OptionSetOptionButtonUIElement Then
                        Dim buttonElement As OptionSetOptionButtonUIElement = CType(subElement, _
                                             OptionSetOptionButtonUIElement)
                        If buttonElement.Text = item.DisplayText Then
                          result = buttonElement
                          Exit For
                        End If
                      End If
                    Next
                    Exit For
                  End If
                Next
              End If
            Catch ex As Exception
              Throw New Exception(String.Format("{0}.GetUIItem Error", ctrl.GetType.Name), ex)
            End Try
            Return result
          End Function
          <Extension()> _
          Public Function IsItemEnabled(ByVal ctrl As Infragistics.Win.UltraWinEditors.UltraOptionSet, _
                                        ByVal dataValue As Object) As Boolean
            Dim result As Boolean = False
            Try
              If dataValue Is Nothing Then Throw New ArgumentNullException("The data value may not be null")
              Dim buttonElement As OptionSetOptionButtonUIElement = ctrl.GetUIItem(dataValue)
              If buttonElement IsNot Nothing Then
                result = buttonElement.Enabled
              End If
            Catch ex As Exception
              Throw New Exception(String.Format("{0}.IsItemEnabled Error", ctrl.GetType.Name), ex)
            End Try
            Return result
          End Function
          <Extension()> _
          Public Sub EnableItem(ByVal ctrl As Infragistics.Win.UltraWinEditors.UltraOptionSet, _
                                ByVal dataValue As Object, ByVal enabled As Boolean)
            Try
              If dataValue Is Nothing Then Throw New ArgumentNullException("The data value may not be null")
              Dim buttonElement As OptionSetOptionButtonUIElement = ctrl.GetUIItem(dataValue)
              If buttonElement IsNot Nothing Then
                buttonElement.Enabled = enabled
              End If
            Catch ex As Exception
              Throw New Exception(String.Format("{0}.EnableItem Error", ctrl.GetType.Name), ex)
            End Try
          End Sub

        2. Add code like this to the ValueChanged event handler so that disabled items cannot be selected:

         Private Sub UltraOptionSet1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                          Handles UltraOptionSet1.ValueChanged
            If UltraOptionSet1.Value IsNot Nothing Then
               If UltraOptionSet1.IsItemEnabled(UltraOptionSet1.Value) Then
                  UltraOptionSet1.Tag = UltraOptionSet1.Value ' Store the last valid selected value.
                  ' Do something else if you need to.
               Else
                  UltraOptionSet1.Value = UltraOptionSet1.Tag
                  UltraOptionSet1.FocusedIndex = UltraOptionSet1.Items.GetIndex(UltraOptionSet1.Tag)
                  UltraOptionSet1.Refresh()
               End If
             End If
           End If
        End Sub

        3. Enable or disable items like this:

        UltraOptionSet1.EnableItem(5, False)

        This example will disable the first option item with a data value of 5.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Matrikon
Favorites
0
Replies
8
Created On
May 12, 2011
Last Post
15 years, 4 months ago

Suggested Discussions

Created by

Created on

May 12, 2011 4:33 AM

Last activity on

Feb 24, 2026 2:25 PM