Emil Dumbazu Emil Dumbazu - 6 months ago 32
C# Question

Index of the current row in DataGridView

I have 2 DataGridViews and I transfer data between them. My question is: How can i move the index of datagridview1 row to next one after the data has been transfered.


int index = 0;
int index1 = 0;
for (int i = 0; i < produseDataGridView.CurrentCell.RowIndex; i++)
index = produseDataGridView.Rows[i].Cells["dprodus"].RowIndex;
for (int j = 0; j < produse_magazinDataGridView.CurrentRow.Index; j++)
index1 = produse_magazinDataGridView.Rows[j].Cells["produs"].RowIndex;
produseDataGridView.CurrentCell = produseDataGridView.Rows[index + 1].Cells[0];
produse_magazinDataGridView.CurrentCell = produse_magazinDataGridView.Rows[index1 + 1].Cells[0];


I'm not sure what you mean by "how can i move the index of datagridview1 row to next".

Index is just a integer in your code. If you meant to write "how to select the next row" then its:

produseDataGridView.Rows(Index + 1).Selected = True;
produse_magazinDataGridView.Rows(Index1 + 1).Selected = True;