Israel

Israel

  • 631
  • 1.3k
  • 217.4k

Display before any row using "Button"

Jan 18 2020 7:44 PM
Hi,
 
I was writing these codes to display the before any row. For example:
 
Samia
Alam
Shell
 
Then when I click on "Shell" its display on textbox "Alam". If I click on "Alam" its display "Samia".
 
These codes work perfectly using the datagrid. How can I do using Button.
  1. private void DGVTest_CellClick(object sender, EventArgs e)  
  2. {  
  3. if (e.RowIndex == 0)   
  4. {  
  5. lblID.Text = string.empty;  
  6. txtName.Text = string.empty;  
  7. }  
  8. else if (e.RowIndex >= 1)  
  9. {  
  10. DataGridViewRow row = this.dgvTest.Rows[e.RowIndex - 1];  
  11. if (row != null)  
  12. {  
  13. lblID.Text = row.Cells["id"].Value.ToString();  
  14. txtName.Text = row.Cells["name"].Value.ToString();  
  15. }  
  16. }  

Answers (3)