Click here to Skip to main content
15,346,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on data grid view I face issue I can't solve it

so please if you can help me please

I have data grid view read barcode it read barcode success and display items data

issue when change quantity and press enter then I need it go to next empty row

on first cell Code to get new barcode by scanner

but this not happen

what happen is cursor go to next row cell number 4

so please How to make first cell focus next row instead of cell number 4

What I have tried:

C#
private void GridTrxInvF_CellValueChanged_1(object sender, DataGridViewCellEventArgs e)
     {
    
    
         if (GridTrxInvF.CurrentCell != null && GridTrxInvF.CurrentCell.ColumnIndex == GridTrxInvF.Columns["displayQty"].Index && GridTrxInvF.CurrentCell.Value != null)
    
         {
    
             int col = GridTrxInvF.CurrentCell.ColumnIndex;
             int row = GridTrxInvF.CurrentCell.RowIndex;
             int nRows = GridTrxInvF.Rows.Count - 1;
             int nCol = GridTrxInvF.Columns.Count - 1;
    
    
             if (nCol == col && nRows == row)
             {
                 GridTrxInvF.CurrentCell = GridTrxInvF[0, 0];
             }
             else if (nRows == row)
             {
                 GridTrxInvF.CurrentCell = GridTrxInvF[col + 1, 0];
             }
             else
             {
    
    
    
    
                 var row2 = GridTrxInvF.Rows[GridTrxInvF.RowCount - 1];
    
    
    
                 GridTrxInvF.CurrentCell = row2.Cells[1];
    
    
                 GridTrxInvF.CurrentCell.Selected = true;
    
                 GridTrxInvF.BeginEdit(true);
                   
             }
    
         }
    
    
     }
 protected override bool ProcessDataGridViewKey(System.Windows.Forms.KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape)
         _CellEnteredFromEsc = true;
     else
         _CellEnteredFromEsc = false;
     int TimesToSend = 1;
     if (this.CurrentRow == null) return base.ProcessDataGridViewKey(e);
     else if (e.KeyCode == Keys.Enter)
     {
         
         if (this.CurrentCell.ColumnIndex == _Get_The_Last_Visibale_Index() && this.ValidateRequiredCellsInRow() && this.ValidateInRow() && this.CurrentCell.RowIndex == (this.Rows.Count - 1))
         {
             this.AddNewRow();
         }
         else
         {
             for (int i = this.CurrentCell.ColumnIndex + 1; i < this.Columns.Count; i++)
             {
                 if (!this.Columns[i].Visible) continue;
                
                  
                    
                 if (this.Columns[i].Tag != null && (this.Columns[i].Tag as ColumnTag).IsDisabled)
                 {
                     if (this[i, this.CurrentCell.RowIndex] == this[this.Columns.Count - 1, this.Rows.Count - 1] && this.ValidateRequiredCellsInRow() && this.ValidateInRow())
                     {
                         this.AddNewRow();
                         return false;
                     }
                     else TimesToSend++;
                 }
                 else break;
             }
             if (!_StopCellTab)
                SendKeys.Send("{TAB " + TimesToSend + "}");
                                 this._CellEnteredFromTab = true;
         }
         return false;
     }
      
       
     else if (bIsGridValid)
         return base.ProcessDataGridViewKey(e);
     return false;
 }
Posted
Comments
ahmed_sa 26-Sep-21 20:58pm
   
i found issue do that
SendKeys.Send("{TAB " + TimesToSend + "}");
but problem how to focus first cell on next row without using tab key send

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