Solved

Winform Button focus on Up/Down Arrow key

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

20 Experts available now in Live!

Get 1:1 Help Now