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

Temporally disable arrow keys

1 Answer 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Iron
Veteran
Claude asked on 06 Mar 2021, 11:59 PM

I want to temporarily disable the arrow keys in the grid.  When a row is selected, I do some image processing for that row, which typically takes .25  to 2 seconds.  During that processing time, I want to disable the arrow keys during processing and then enable them when done.  I created a bool isBusy Flag for the processing, but I cannot add that to the below custom behavior.  Any suggestions?  Is there a way to toggle the Custom behavior?

public class CustomGridBehavior : BaseGridBehavior

        {
            public override bool ProcessKey(KeyEventArgs keys__1)
            {
              
                switch (keys__1.KeyCode)
                {
                    case Keys.Up:
                    case Keys.Down:
                    case Keys.Left:
                    case Keys.Right:
                        {
                            return false;
                        }

                    default:
                        {
                            return base.ProcessKey(keys__1);
                        }
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Mar 2021, 08:28 AM

Hello, Claude,

I have prepared a sample code snippet demonstrating how to use the RadGridView.Tag property to store any useful information that can be used during the application's execution. Thus, we wouldn't need a Boolean flag:
        public RadForm1()
        {
            InitializeComponent();

            this.radGridView1.GridBehavior = new CustomGridBehavior();
        }

        bool isBusy = false;

        private void radButton1_Click(object sender, EventArgs e)
        {
            isBusy = !isBusy;
            if (isBusy)
            {
                this.radGridView1.Tag = "isBusy";
            }
            else
            {
                this.radGridView1.Tag = null;
            }
        }
    }

    public class CustomGridBehavior : BaseGridBehavior
    {
        public override bool ProcessKey(KeyEventArgs keys__1)
        {
            switch (keys__1.KeyCode)
            {
                case Keys.Up:
                case Keys.Down:
                case Keys.Left:
                case Keys.Right:
                    {
                        if (this.GridControl.Tag != null && this.GridControl.Tag == "isBusy")
                        {
                            return false;
                        }
                        return base.ProcessKey(keys__1);
                    }
                default:
                    {
                        return base.ProcessKey(keys__1);
                    }
            }
        }
    }

If the mentioned image processing is a time consuming operation, I would suggest you to consider using a BackgroundWorker and do the work outside the main UI thread. A sample approach for executing long-lasting operations is demonstrated in the following help article: https://docs.telerik.com/devtools/winforms/controls/track-and-status-controls/waitingbar/using-waitingbar-with-a-background-worker 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or