Solved

Winform Button focus on Up/Down Arrow key

Posted on 2007-11-14
5
1,405 Views
Last Modified: 2013-12-17
In Winform  I have 2 buttons . When I use the UP/Down arrow key it chnages the focus from one button to other.I want to disable this button focus chnage when Up/Down arrow key is hit on the keyboard.

Instead I wanted to us for Datagrid. So I worte the following code for Scrolling the Grid.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
                        
      switch (keyData)
      {
            case Keys.Down:
                 SelectNextGridRow();
                 break;
            case Keys.Up:
                   SelectNextGridRow();
                 break;
      }
      return base.ProcessCmdKey(ref msg, keyData);
}

The focus on buttons also keeps chnaging when I hit Up/Down Key. How do I disable this?

0
Comment
Question by:AdibRahman77
  • 2
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 20281883
This part:

    return base.ProcessCmdKey(ref msg, keyData);

causes the default action for the keys to be processed.

If you don't want something to happen for certain keys then you need to NOT call the above line of code for them...

0
 
LVL 10

Assisted Solution

by:Nash2334
Nash2334 earned 150 total points
ID: 20281939
Idle_Mind is correct, just move the return to the default action and you should be OK.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
                       
      switch (keyData)
      {
            case Keys.Down:
                 SelectNextGridRow();
            case Keys.Up:
                   SelectNextGridRow();
            default:
                   return base.ProcessCmdKey(ref msg, keyData);
      }
}
0
 
LVL 10

Expert Comment

by:Nash2334
ID: 20281944
Forgot the return statement for the up down keys...

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
                       
      switch (keyData)
      {
            case Keys.Down:
                 SelectNextGridRow();
                 return true;
            case Keys.Up:
                   SelectNextGridRow();
                   return true;
            default:
                   return base.ProcessCmdKey(ref msg, keyData);
      }
}
0
 
LVL 3

Assisted Solution

by:Aurora27
Aurora27 earned 50 total points
ID: 20283268
yep..returning a base calls memeber fn. always overrides the everthing that was done before :)

CT.
0
 
LVL 3

Expert Comment

by:Aurora27
ID: 20285668
Thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now