Date and Calculator with alternate hotkey

3 posts, 1 answers
  1. A-Telerik-User
    A-Telerik-User avatar
    5 posts
    Member since:
    Oct 2013

    Posted 19 Jul 2019 Link to this post

    Good day,

    The little calendar could be activated/popup with hotkey F4 for GridViewDatetimeColumn and the calculator for GridViewCalculatorColumn. Is this hotkey changeable, said change to F2 to bring up these?

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3898 posts

    Posted 23 Jul 2019 Link to this post

    Hello,  

    Indeed, by default, pressing F4 while RadCalculatorEditor is active, will show the popup calendar. In order to prevent this when pressing F4 and execute the same logic after F2 is pressed, you can refer to the following code snippet:

    public RadForm1()
    {
        InitializeComponent();
     
        GridViewCalculatorColumn column = new GridViewCalculatorColumn("Calculator column");
        this.radGridView1.Columns.Add(column);
     
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
        this.radGridView1.Rows.Add(3.14159);
        this.radGridView1.Rows.Add(2.71828);
        this.radGridView1.Rows.Add(1.41421);
        this.radGridView1.Rows.Add(0.57721);
        this.radGridView1.Rows.Add(4.66920);
        this.radGridView1.Rows.Add(3.27582);
        this.radGridView1.Rows.Add(0.56714);
     
        this.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
    }
     
    private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadCalculatorEditor calcEditor = e.ActiveEditor as RadCalculatorEditor;
        if (calcEditor != null)
        {
            RadCalculatorEditorElement el = calcEditor.EditorElement as RadCalculatorEditorElement;
     
            el.EditorContentElement.TextBoxItem.PreviewKeyDown -= TextBoxItem_PreviewKeyDown;
            el.EditorContentElement.TextBoxItem.PreviewKeyDown += TextBoxItem_PreviewKeyDown;
             
            el.PopupOpening -= el_PopupOpening;
            el.PopupOpening += el_PopupOpening;
        }
    }
     
    private void el_PopupOpening(object sender, CancelEventArgs e)
    {
        e.Cancel = cancel;
        cancel = false;
    }
     
    bool cancel = false;
     
    private void TextBoxItem_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyData == Keys.F4)
        {
            cancel = true;
        }
        else if (e.KeyData == Keys.F2)
        {
            RadCalculatorEditor calcEditor = this.radGridView1.ActiveEditor as RadCalculatorEditor;
            RadCalculatorEditorElement el = calcEditor.EditorElement as RadCalculatorEditorElement;
            el.ShowPopup();
        }
    }

    Feel free to use a similar approach for the date time column as well.
     
    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. A-Telerik-User
    A-Telerik-User avatar
    5 posts
    Member since:
    Oct 2013

    Posted 23 Jul 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks for the solution. 

    Beside i have found an alternative with the RadShortcut which i could apply to columns' calculator and calendar popup.

Back to Top