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

SpinEditor Always Changing my Value

7 Answers 221 Views
SpinEditor
This is a migrated thread and some comments may be shown as answers.
Chris Kirkman
Top achievements
Rank 1
Chris Kirkman asked on 29 Dec 2010, 08:41 PM
I have a min and max allowable value set.  When the user enters "110" and the min is 0 and the max is 100, the control automatically adjusts the value to "100", the max.

Is there a way to stop this from happening?

7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 29 Dec 2010, 08:50 PM
Hi Chris,
This is expected from this control. If you would like to remove this then I'd suggest setting the Max to a higher value and then validating the value as you would with a textBox.
Hope that helps but let me know if you have any further questions
Richard
0
Chris Kirkman
Top achievements
Rank 1
answered on 29 Dec 2010, 08:59 PM
Just my opinion, but I don't understand the logic in having a control that enforces a max and min value on tab click, but not when the user is tying the value itself.  In the core Windows textbox, if I set the max number of characters to 5, then I can only enter 5 chars...period.  It doesn't allow me to enter 10 and then truncate what I've entered back down to 5 on tabbing out of the control.

It seems logical that, at a minimum, I should be able to receive an event notification from the control that IT is changing the value (and not the user changing the value).  Do you know of an event that will tell me when the control decides to "validate" and change my invalid 110 to a 100?
0
Richard Slade
Top achievements
Rank 2
answered on 29 Dec 2010, 09:40 PM
Hi Chris,

I beleive that this is the case because whilst you are typing, the control is still editing. The max value is changing, whilst you have compared it with a textbox that validates against string length which is different.

you can subscribe to the property changed event and see the value changed
AddHandler Me.RadSpinEditor1.SpinElement.PropertyChanged, AddressOf PropertyChanged
Public Sub PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
    If e.PropertyName = "Value" Then
        MessageBox.Show("Value Changed")
    End If
End Sub

However, to get over your issue, I'd suggest something like this. You just need to add an ErrorProvider..
In form load or similar
AddHandler Me.RadSpinEditor1.SpinElement.TextBoxItem.Validating, AddressOf RadSpinEditor_TextValidating
AddHandler Me.RadSpinEditor1.SpinElement.TextBoxItem.Validated, AddressOf RadSpinEditor_TextValidated
AddHandler Me.RadSpinEditor1.Leave, AddressOf RadSpinEditor_Leave
Me.RadSpinEditor1.Minimum = 0
Me.RadSpinEditor1.Maximum = 999

Public Sub RadSpinEditor_Leave(ByVal sender As Object, ByVal e As EventArgs)
    Me.RadSpinEditor1.SpinElement.Validate()
End Sub

Public Sub RadSpinEditor_TextValidating(ByVal sender As Object, ByVal e As CancelEventArgs)
    If Me.RadSpinEditor1.Value > 100 Then
        Me.ErrorProvider1.SetError(Me.RadSpinEditor1, "Value cannot be over 100")
        e.Cancel = True
        Me.RadSpinEditor1.SpinElement.TextBoxItem.SelectionStart = Me.RadSpinEditor1.SpinElement.TextBoxItem.Text.Length
    End If
End Sub

Public Sub RadSpinEditor_TextValidated(ByVal sender As Object, ByVal e As EventArgs)
    Me.ErrorProvider1.SetError(Me.RadSpinEditor1, "")
End Sub

Hope that helps but let me know if you have further questions
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 31 Dec 2010, 10:44 AM
Hi Chris,

Did you find this helped? If so, please remember to mark as answer,
thanks
Richard
0
Peter
Telerik team
answered on 04 Jan 2011, 10:24 AM
Hi Chris Kirkman,

Thank you Richard for your solution.

In order to make our RadSpinEditor more convenient for our users, we mimic the behavior of the standard Microsoft NumericUpDown control. We cannot validate the way the user types a value. For example, if one wants to enter 17,8 and starts typing 178, then presses the left arrow key and finally types ','.

You can use the solution provided by Richard.

I hope this helps.

Kind regards,
Peter
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Chris Kirkman
Top achievements
Rank 1
answered on 04 Jan 2011, 02:37 PM

Thanks guys.  I ended up implementing my own control, using the RadSpinEditor as the base control.  The users are much happier with it and its behavior.

One thing I'd recommend however; I wouldn't expect the caller of a control to have to use string comparisons to know what value is changed in the PropertyChanged() event.  That seems really messy to me.  I'd prefer that perhaps the event arguments to a PropertyChanged() event to contain maybe an Enum with the value containing what property changed.

For instance.  Have the following enum..

enum PropertyTypeEnum { Value, Text, Color, Size }

and then in your PropertyChanged(object sender, PropertyChangedEventArgs e) have a property called

e.PropertyType of Type (PropertyTypeEnum) so that I could just do something like the following...

if(e.PropertyType == PropertyTypeEnum.Value)
{
    .... do stuff here
}

0
Peter
Telerik team
answered on 07 Jan 2011, 12:37 PM
Hi Chris Kirkman,

Thank you for writing back.

I would like to inform that PropertyChanged is a method of the Microsoft INotifyPropertyChanged interface and its parameters cannot be changed. In our TPF, we are using RadPropertyChanged where we implement a comparison between types, for example:

protected override void OnPropertyChanged(RadPropertyChangedEventArgs e)
{
      if (e.Property == RadElement.VisibilityProperty)
      {

I hope this helps.

Kind regards,
Peter
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
SpinEditor
Asked by
Chris Kirkman
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Chris Kirkman
Top achievements
Rank 1
Peter
Telerik team
Share this question
or