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

SpinEditor sound when enter key is hit

1 Answer 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 09 Jan 2012, 06:48 PM
If you end edit on any spin edit control in a gridview it plays the windows ding sound. Is there any way stop this?

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 12 Jan 2012, 10:03 AM
Hi Daniel,

Thank you for writing.

This sound comes from the standard text box which is embedded in the spin editor. You can prevent this sound by setting the SuppressKeyPress property of the text box to true. This property is available in the KeyDown event arguments. Here is an example of how to subscribe to this event and set this property:
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    GridSpinEditor editor = e.ActiveEditor as GridSpinEditor;
    GridSpinEditorElement element = editor.EditorElement as GridSpinEditorElement;
    element.TextBoxItem.KeyDown += new KeyEventHandler(element_KeyDown);
}
 
void element_KeyDown(object sender, KeyEventArgs e)
{
    RadTextBoxItem tb = sender as RadTextBoxItem;
    GridSpinEditorElement spinElement = tb.Parent.Parent as GridSpinEditorElement;
    if (e.KeyCode == Keys.Enter)
    {
        e.SuppressKeyPress = true;
        if ((Convert.ToDecimal(spinElement.TextBoxItem.Text) > spinElement.MinValue))
        {
            spinElement.Value = spinElement.MaxValue;
        }
        else if ((Convert.ToDecimal(spinElement.TextBoxItem.Text) < spinElement.MinValue))
        {
            spinElement.Value = spinElement.MinValue;
        }
        else
        {
            spinElement.Value = Convert.ToDecimal(spinElement.TextBoxItem.Text);
        }
    }
}

Since suppressing the key press will prevent submitting your data, this should be done manually (as shown in the code above).

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
 
Regards,
Stefan
the Telerik team

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

Tags
GridView
Asked by
Dave
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or