Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Previous value in UltraComboEditor

Previous value in UltraComboEditor

New Discussion
Amiram Korach
Amiram Korach asked on Oct 18, 2011 3:35 PM

Hi all,

Is there a way to retreive the previously selected value from the UltraComboEditor after the user chooses a new value and before the value is committed?
Or is there a way to cancel the user’s selection?

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Dec 24, 2008 3:02 PM

    Well, if the control is bound, you can probably get the old value from the data source and compare that to the value of the control. The control itself doesn't keep track of the old value.

    And I don't know of any way to cancel the selection, but if you use UltraCombo, instead of UltraComboEditor, you can disable rows to prevent the user from selecting them. 

     

    • 0
      Amiram Korach
      Amiram Korach answered on Dec 24, 2008 3:29 PM

      What is the event that I should use? The control is bound so I need an event which when it happen the value in the data is different than the control value.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Dec 24, 2008 7:02 PM

        ValueChanged seems like a good candidate. 

      • 0
        Amiram Korach
        Amiram Korach answered on Dec 25, 2008 8:34 AM

        I can cache the old value and make my own ValueChanging event like that: (sample attached)

        public event EventHandler<CancelNewEventArgs> ValueChanging;

        protected object oldValue;

        private bool skipValueChanging;

        protected override void OnValueChanged(EventArgs args)

        {

        if (!skipValueChanging)

        {

        CancelNewEventArgs e = new CancelNewEventArgs();

        OnValueChanging(e);

        if (e.Cancelled)

        {

        skipValueChanging = true;

         

        if (oldValue == null)

        this.SelectedItem = null;

        else

         

        Value = oldValue;

         

        skipValueChanging = false;

        }

        }

        oldValue = Value;

        base.OnValueChanged(args);

        }

        protected virtual void OnValueChanging(CancelNewEventArgs args)

        {

        if (ValueChanging != null)

        {

        ValueChanging(this, args);

        }

        }

        ComboEditorRollback

      • 0
        Amiram Korach
        Amiram Korach answered on Dec 25, 2008 1:42 PM

        My code still has a problem. If the control is bound, the OldValue should get the value of "Value", but ValueChanged is not fired as a result of binding change, so you always get a null value if you cancel the change. I'm using the combo editor inside a UserControl so I have a property that explicitly sets the Value property, but whoever want to use this need to fix it.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jan 5, 2009 2:14 PM

        What exactly do you mean by "ValueChanged is not fired as a result of binding change"? ValueChanged should fire any time the Value of the control changes. Are you saying you are binding the control to a new data source? Or just that the value of the bound field changed? 

      • 0
        Amiram Korach
        Amiram Korach answered on Jan 5, 2009 2:52 PM

        ValueChanged is fired only when the user changes the value, not when you bind and the binding changes the value.

        We already solved the problem like that:

        public

        partial class MyComboEditor : UltraComboEditor

        {

        /// <summary>

        /// Occurs when the value is about to be changed

        /// </summary>public event EventHandler<CancelNewEventArgs> ValueChanging;

        /// <summary>

        /// Holds the previous value in order to allow rollback

        /// </summary>protected object m_OldValue;

        private bool m_SkipValueChanging;public MyComboEditor()

        {

        InitializeComponent();

        m_OldValue = null;

        }

        /// <summary>

        /// Rollbacks the value changing if ValueChanging was cancelled

        /// </summary>

        /// <param name="args"></param>protected override void OnValueChanged(EventArgs args)

        {

        if (!m_SkipValueChanging)

        {

        CancelNewEventArgs e = new CancelNewEventArgs();

        OnValueChanging(e);

        if (e.Cancelled)

        {

        m_SkipValueChanging = true;

        if (m_OldValue == null)this.SelectedItem = null;

        else

        Value = m_OldValue;

        m_SkipValueChanging = false;

        }

        }

        base.OnValueChanged(args);

        }

        protected virtual void OnValueChanging(CancelNewEventArgs args)

        {

        if (ValueChanging != null)

        {

        ValueChanging(this, args);

        }

        }

        public override object Value

        {

        get

        {

        return base.Value;

        }

        set

        {

        base.Value = value;

        m_OldValue = Value;

        }

        }

        }

      • 0
        Ulf Ã…kerstedt
        Ulf Ã…kerstedt answered on Oct 18, 2011 3:35 PM

        And here is approximately the same code in VB.Net.
        I haven't used/verified this actual code since I did something different, but figured I'd post this as a starter help for anyone in the need for it.

            Partial Public Class MyComboEditor
                Inherits UltraComboEditor

                ''' <summary>
                ''' Occurs when the value is about to be changed
                ''' </summary>
                Public Event ValueChanging As EventHandler(Of CancelEventArgs)

                ''' <summary>
                ''' Holds the previous value in order to allow rollback
                ''' </summary>
                Protected _OldValue As Object
                Private _SkipValueChanging As Boolean

                Public Sub New()
                    InitializeComponent()
                    Me._OldValue = Nothing
                End Sub

                ''' <summary>
                ''' Rollbacks the value changing if ValueChanging was cancelled
                ''' </summary>
                Protected Overrides Sub OnValueChanged(ByVal args As EventArgs)
                    If Me._SkipValueChanging Then Return

                    Dim e As CancelEventArgs = New CancelEventArgs()
                    OnValueChanging(e)
                    If e.Cancel Then 'Roll back the value change if ValueChanging was cancelled
                        Me._SkipValueChanging = True
                        If Me._OldValue Is Nothing Then
                            Me.SelectedItem = Nothing
                        Else
                            Me.Value = _OldValue
                        End If
                        Me._SkipValueChanging = False
                    End If

                    MyBase.OnValueChanged(args)
                End Sub

                Protected Overridable Sub OnValueChanging(ByVal args As CancelEventArgs)
                    RaiseEvent ValueChanging(Me, args)
                End Sub

                Public Overrides Property Value As Object
                    Get
                        Return MyBase.Value
                    End Get
                    Set(ByVal value As Object)
                        MyBase.Value = value
                        Me._OldValue = value
                    End Set
                End Property
            End Class

         

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Amiram Korach
Favorites
0
Replies
8
Created On
Oct 18, 2011
Last Post
14 years, 5 months ago

Suggested Discussions

Created by

Created on

Oct 18, 2011 3:35 PM

Last activity on

Feb 23, 2026 3:13 PM