This is a migrated thread and some comments may be shown as answers.

SpinEditor gets stuck when cancelling ValueChanging

3 Answers 79 Views
SpinEditor
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 06 Jan 2012, 05:04 PM
I have a RadSpinEditor with the following ValueChanging event handler:

private void CrewQtyText_ValueChanging(object sender, Telerik.WinControls.UI.ValueChangingEventArgs e)
{
     foreach (Telerik.WinControls.UI.GridViewRowInfo row in RequiredRolesGrid.Rows)
     {
          if (Convert.ToInt16(row.Cells["Workgroup"].Value) > Convert.ToInt16(e.NewValue))
          {
               e.Cancel = true;
               break;
          }
     }
     if(!e.Cancel)
          foreach (Telerik.WinControls.UI.GridViewRowInfo row in RequiredEquipGrid.Rows)
          {
                if (Convert.ToInt16(row.Cells["Workgroup"].Value) > Convert.ToInt16(e.NewValue))
                {
                     e.Cancel = true;
                     break;
                }
           }
 
           if (e.Cancel)
                 MessageBox.Show("Requirements already exist for workgroup " + e.OldValue);
}

Basically if the user has other requirements that depend on the value in the spin editor I don't want them to be allowed to change the spinner.  That seems to work fine, but the buttons on the spinner get stuck once the operation has been Cancelled, and the next time that button is pressed it behaves as though it was in it's old state.  For example (assuming the spinner has an integer value), I increment the spinner to 3 (#1 from screen shot).  Let's say the user has a requirement that prevents them from lowering the spinner value below 2.  Now I decrement the spinner twice (#2 from screen shot).  The first one works, lowering the value to 2.  The second click causes the operation to be canceled.  Now say I increment the value to 5 (#3 from screen shot, note 'depressed' spinner button').  The NEXT time I try to decrement (just once), the value returns to 2 (#4 from screen shot), the last value that caused the operation to be cancelled.  I would expect it to return to 4, 3, then 2.  You can see that the down button on the spinner stays highlighted after the operation is cancelled.  I know this probably sounds confusing.  Please try to follow the screen shot provided, and let me know if you need more detail.

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 09 Jan 2012, 10:46 AM
Hello Eric,

Thank you for writing.

This is a feature of our themes. In your case RadSpinEditor buttons stay in pressed state, because the modal dialog intercepts all events. You can work around the issue by setting the IsMouseDownProperty to False, here is a sample:

private void CrewQtyText_ValueChanging(object sender, EventArgs e)
{
    .....
        CrewQtyText.SpinElement.UpButton.SetValue(RadElement.IsMouseDownProperty, false);
        CrewQtyText.SpinElement.DownButton.SetValue(RadElement.IsMouseDownProperty, false);
         
if (e.Cancel)
                 MessageBox.Show("Requirements already exist for workgroup " + e.OldValue);
}

I hope this helps.

Regards,
Peter
the Telerik team

SP1
of Q3’11 of RadControls for WinForms is available for download (see what's new).
0
Eric
Top achievements
Rank 1
answered on 09 Jan 2012, 03:58 PM
Thank you for your response.  UpButton and DownButton are obsolete, it's ButtonUp and ButtonDown now.  

So it would be...
CrewQtyText.SpinElement.ButtonUp.IsMouseDown = false;
CrewQtyText.SpinElement.ButtonDown.IsMouseDown = false;

This removes the depressed look on the down button.  It didn't actually fix my problem, which is related to the MessageBox as it turns out.  For some reason when the MessageBox is shown, the next time I press the down button it will try to decrement 3 from the current value. Funky behavior.  Try it:
private void radSpinEditor1_ValueChanging(object sender, Telerik.WinControls.UI.ValueChangingEventArgs e)
{
    if (Convert.ToInt16(e.NewValue) < 2 && Convert.ToInt16(e.OldValue) >= 2)
    {
        e.Cancel = true;
    }
    if (e.Cancel)
        MessageBox.Show("uh oh");
}





0
Peter
Telerik team
answered on 12 Jan 2012, 10:16 AM
Hi Eric,

Thank you for writing back.

I would like to describe the observed behavior. It is due to the fact that you show the modal MessageBox in the ValueChanged event that comes from RadRepeatButton (RadSpinEditor ButtonDown). RadRepeatButton uses internally a Timer to fire Click events continuously. When the Modal Box (MessageBox) is shown, this timer fires the events, but these events cannot be processed, because at this moment the whole UI thread is stopped by the Modal Box. The timer events are stored in the application message queue. When user closes the MesseageBox, the application processes all events from the message queue. It processes few consecutive timer events that fire RadRepeatButton's Click events - in your case ButtonDown is pressed few times after closing.

Despite our findings and efforts to address the issue, however, we cannot propose a workaround or a fix at the moment. Let us know if you have additional questions.

Regards,
Peter
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Tags
SpinEditor
Asked by
Eric
Top achievements
Rank 1
Answers by
Peter
Telerik team
Eric
Top achievements
Rank 1
Share this question
or