question

ahmedsalah-1628 avatar image
0 Votes"
ahmedsalah-1628 asked karenpayneoregon answered

when change displayqty not go next row first cell code issue it go next row cell number 4

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

  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;
 }

dotnet-csharpdotnet-standarddotnet-adonet
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

can any one help me
issue on that line
SendKeys.Send("{TAB " + TimesToSend + "}");
i found tab 3 so it go 3 next cell extra after add focus on cell 1
so how to replace that
SendKeys.Send("{TAB " + TimesToSend + "}");
by focus on data grid view next row first cell please
i can access next row
but first cell can't do it
because send key

0 Votes 0 ·
JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered JackJJun-MSFT commented

@ahmedsalah-1628, you could try the following code to use Sennkeys to go next row first cell.

   private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
         {
             if (e.ColumnIndex == 3)
             {
                 SendKeys.Send("{TAB}");
                 SendKeys.Send("{UP}");
                   
             }
    
         }

Result:

135513-9999.gif


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.








9999.gif (56.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

when make
SendKeys.Send("{TAB}");
SendKeys.Send("{UP}");
iit add two new row extra
so how to solve this issue please

0 Votes 0 ·

@ahmedsalah-1628, based on my further test, I didn't reproduce your problem. Even if I change the value of cell(3,4), It will not add two extra rows. Do you have any other code to affect it? You could check it again. If the problem still exists, I recommend that you could provide all related your code about your problem.

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

The following out which on the last column edit goes to the next row, first column.

 public class DataGridViewJumper : DataGridView
 {
     protected override void OnKeyUp(KeyEventArgs e)
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (CurrentRow != null)
             {
                 int currentRow = CurrentRow.Index;
                 if (currentRow >= 0 && CurrentCell.ColumnIndex == ColumnCount -1)
                 {
                     CurrentCell = Rows[currentRow].Cells[0];
                 }
             }
         }
         base.OnKeyUp(e);
     }
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.