Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:24:43+00:00 2026-05-18T04:24:43+00:00

I’ve a weird situation while keyboard shortcuts of a button along with datagridview is

  • 0

I’ve a weird situation while keyboard shortcuts of a button along with datagridview is used. Here is the explanation:

I’ve a winform in which there is a datagridview and a save button. Save button has keyboard shortcut Alt+S. I enter some rows in the grid and I validate all the cells on Save button click and if cell value is invalid then I’ll set the focus to that cell. Here is the code used to achieve that:

  for (var index = 0; index < GridView.Rows.Count; index++)
  {
    var itemRow = GridView.Rows[index];

    if (itemRow.Cells[SomeColumn.Name].Value.ToString() == string.Empty)
    {
       GridView.CurrentCell = itemRow.Cells[SomeColumn.Name];
       GridView.Focus();
    }
  }

Above code works fine and sets the focus in the particular cell with cursor when I click on the save button.

But, when I use shortcut key, focus is not set to the cell at all. I’m not sure why it is behaving like this.

Out of curiosity I’ve tested an event of the datagridview. CellLeave event of datagridview is fired when I click on save button, but when I use shortcut for save button it doesn’t get fired.

Why is it behaving like this? any inputs? How can I set the focus when I use shortcuts?

Update: I’ve done a trick to work it properly. I’ve added SaveButton.Focus() code in the button click event of the save button as first line. This is redundant but forcing the grid to lose the focus when user uses short cut key to access this button. This solution is working fine, but not sure what could be the reason for the above situation. Still looking for an answer. 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:24:44+00:00Added an answer on May 18, 2026 at 4:24 am

    Check the key combination on DataGridVeiw keyDown event then if the key is Alt+S then set focus to DatagridVeiw

    Updated:

     private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
     {
        if (e.KeyData == (Keys.Alt | Keys.S))
        {
             //put your code to validate i.e. what u are trying in button click event
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.