Click here to Skip to main content
15,884,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to increase cell quantity using keyboard up and down arrows ?

I work on windows form desktop application using csharp

I face issue I can't increase quantity or decrease using press on key up or down
on datagridview control

when have quantity 1 value then when press up arrow then will be 2

when have quantity 2 then when press down arrow will be 1

so please which event i use it on datagridview windows form csharp to do that

What I have tried:

C#
private void GridTrxInvF_KeyPress(object sender, KeyPressEventArgs e)  
    {  
        int currentNumber = Utilities.ObjectConverter.ConvertToInteger(GridTrxInvF.Rows[GridTrxInvF.CurrentCell.RowIndex].Cells["Quantity"].Value);  
  
        if (e.KeyChar ==(char) Keys.Down)  
        {  
  
            GridTrxInvF.Rows[GridTrxInvF.CurrentCell.RowIndex].Cells["Quantity"].Value = (currentNumber - 1).ToString();  
        }  
        else if (e.KeyChar == (char)Keys.Up)  
        {  
            GridTrxInvF.Rows[GridTrxInvF.CurrentCell.RowIndex].Cells["Quantity"].Value = (currentNumber + 1).ToString();  
        }  
  
    }
Posted
Updated 13-Mar-21 23:36pm
v2
Comments
Richard MacCutchan 14-Mar-21 4:35am    
What is the problem?

1 solution

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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