Using GridViewDecimalColumn

3 posts, 0 answers
  1. Bruno
    Bruno avatar
    2 posts
    Member since:
    Mar 2011

    Posted 12 Sep 2011 Link to this post


    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. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 15 Sep 2011 Link to this post

    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 >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bruno
    Bruno avatar
    2 posts
    Member since:
    Mar 2011

    Posted 15 Sep 2011 Link to this post


    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;
Back to Top