?
Solved

Winform Button focus on Up/Down Arrow key

Posted on 2007-11-14
5
Medium Priority
?
1,432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 900 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 450 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 150 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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