Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
100
Disable +1/-1 using up/down keys in editor.
posted

Hi,

I've got an UltraGrid bound to a custom datasource with decimal data types.  The columns corresponding to the decimal types have their style property set to IntegerNonNegative.

By default, when the cell is in edit mode, you can use the up and down arrow keys to increase or decrease the value by 1.

Is there a simple way of disabling this behavior?

My apologies if this topic is more appropriate for the WinEditors forum.

-Lee

  • 469350
    Verified Answer
    Offline posted

     Hi Lee,

    You need to modiify the KeyActionMappings of the editor for the column. Something like this: 


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridBand rootBand = layout.Bands[0];
                UltraGridOverride ov = layout.Override;

                rootBand.Columns["Int32 1"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.IntegerNonNegative;           
                EditorWithMask editorWithMask = (EditorWithMask)rootBand.Columns["Int32 1"].Editor;

                for (int i = editorWithMask.KeyActionMappings.Count - 1; i >= 0; i--)
                {
                    KeyActionMappingBase kam = editorWithMask.KeyActionMappings[i];
                    MaskedEditAction actionCode = (MaskedEditAction)kam.ActionCode;
                    if (actionCode == MaskedEditAction.UpKeyAction ||
                        actionCode == MaskedEditAction.DownKeyAction)
                    {
                        editorWithMask.KeyActionMappings.Remove(kam);
                    }
                }           
            }

     

    Note that the editors are shared by all of the columns in the grid with the same Style. So if you get the editor from the column's Editor property like I am doing here, this will affect all of the columns in the grid that are using that editor, which is probably what you want in a case like this. If not, you would need to declare a new EditorWithMask and do the same thing, then assign it to the column.