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
40
Closing the column chooser with the ESC Key or Cancel Key
posted

Is there a way to close the column chooser ( ultraGrid1.ShowColumnChooser) using the ESC key or Cancel Key?

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    I don't think there is any built-in option for this. But I wonder if you could do it by hooking some event of the dialog. I assume you are using the grid's built-in ColumnChooser. You could handle the ultraGrid1_BeforeColumnChooserDisplayed of the grid. This event gives you a reference to the column choser dialog. I tried this out and this seems to work: 

     

    private void ultraGrid1_BeforeColumnChooserDisplayed(object sender, BeforeColumnChooserDisplayedEventArgs e)
            {
                e.Dialog.KeyPreview = true;           
                e.Dialog.KeyDown += new KeyEventHandler(ColumnChooserDialog_KeyDown);
                e.Dialog.Closed += new EventHandler(Dialog_Closed);
            }

            void ColumnChooserDialog_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Escape)
                {
                    ((Form)sender).Close();
                }
            }

            void Dialog_Closed(object sender, EventArgs e)
            {
                ((Form)sender).KeyDown -= new KeyEventHandler(ColumnChooserDialog_KeyDown);
            }

Children