Solved

Winform Button focus on Up/Down Arrow key

Posted on 2007-11-14
5
1,409 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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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