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