Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have a DataGridView in my form which allows to edit details of a product. What I want to know is how to prevent navigation to the cell in
XML
the next row by using the arrow keys while the DataGridView is in editable mode. I've used the following code snippet, but it doesn't work for me. Can anyone help me to sort out this issue?


 if (canedit = true && e.KeyCode == Keys.Down || e.KeyCode == Keys.Up)
          {
              e.Handled = true;
              e.SuppressKeyPress = true;

          }

in here canedit is a boolean value
Posted
Updated 21-Oct-22 3:30am

Hi,
Use following-

C#
void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyData & Keys.KeyCode)
            {
                case Keys.Up:
                case Keys.Right:
                case Keys.Down:
                case Keys.Left:
                    e.Handled = true;
                    e.SuppressKeyPress = true;
                    break;
            }

        }
 
Share this answer
 
Comments
Harindu Karunatillake 27-Nov-14 4:30am    
NO it's not working, what I'm require is , I want to edit the cell in the selected row only. Other rows should be disable when editing the cell in selected row.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900