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

Using GridViewDecimalColumn

2 Answers 182 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 12 Sep 2011, 04:09 PM

Hello,

In a gridview, I am using a GridViewDecimalColumn to display numeric data.

The problem is that I would like to be able to use the two arrows key (Up and Down) to scroll on my GridView, and not have my data being increased or decreased when using them. Is there a way to disable the increasing and decreasing of data when using these keys ?

If not, is there a possibility to use another column type (GridViewTextBoxColumn for example) and then, how can I manage it so only numeric values can be typed into it ?

Thank you for your help.

2 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 15 Sep 2011, 09:14 AM
Hello Bruno,

Thank you for writing.

You can have a column with only numeric values without using the GridViewDecimalColumn in two ways.
1. You could use a GridViewMaskBoxColumn with MaskType set to Numeric and Mask set to N0 (N zero).
2. You can use a GridViewTextBoxColumn and handle the KeyPress. Here is a code snippet which demonstrates how to do this:

private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
  if (e.ColumnIndex == 0)
  {
    RadTextBoxEditor editor = e.ActiveEditor as RadTextBoxEditor;
    RadTextBoxElement element = editor.EditorElement as RadTextBoxElement;
 
    element.KeyPress += new KeyPressEventHandler(element_KeyPress);
  }
}
 
void element_KeyPress(object sender, KeyPressEventArgs e)
{
  if (!Char.IsNumber(e.KeyChar))
  {
    e.Handled = true;
  }
}

I hope this will help you. if you have further questions, I would be glad to help. Greetings,
Ivan Petrov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Bruno
Top achievements
Rank 1
answered on 15 Sep 2011, 09:20 AM

Thank you for your answer.

Finally, I solved the problem by acceding to the SpinEditor of the column, and setting property InterceptArrowKeys to false.

Code sample :

GridSpinEditor spinEditor = this.radGridView.ActiveEditor as GridSpinEditor;
((RadSpinElement)spinEditor.EditorElement).InterceptArrowKeys = false;
Tags
General Discussions
Asked by
Bruno
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Bruno
Top achievements
Rank 1
Share this question
or