Israel

Israel

  • 701
  • 1.3k
  • 217.3k

How to display the before any row

Aug 25 2019 5:01 AM
Hi,
 
I have a datagridview with five records.  
 
ID    Name    Salary
1      Samira   1.000,00
2      Idia        5.000,00
3      Wassa   2.000,00
4      Sheton   2.300,00
5      Elija       4.000,00 
 
When I want to display the Id number 3 on my textboxes I do this: 
private void dgvTest_CellClick(object sender, DataGridViewCellEventArgs e)
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dgvTest.Rows[e.RowIndex];
if (dgvTest != null)
 
lblID.Text = row.Cells["id"].Value.ToString();
txtName.Text = row.Cells["name"].Value.ToString();
txtSalary.Text = row.Cells["salary"].Value.ToString(); 
 
But the problem is how can I display the before one record selected. Mean to show the ID number 2 clicking on ID number 3. 
I can click on ID number 5 but I want to be displayed on my textboxes the ID number 4

Answers (6)