Chris Anderson

Chris Anderson

  • NA
  • 93
  • 8.3k

Open a UserControl when a column button is clicked (Windows App Form)

Feb 10 2021 9:02 PM
When a column button is clicked I wonder how I can get that data for that particular row.

For instance below I would like to get the data for the object of Puppypuppy and pass on the data to a UserControl (which in my case is a simple window that I want to populate with the data from the clicked button)
 
 The code for the event when a button is clicked:
  1. private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)  
  2. {  
  3.     var senderGrid = (DataGridView)sender;  
  4.   
  5.     if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&  
  6.         e.RowIndex >= 0)  
  7.     {  
  8.         // How to get the data of an object when a column button is clicked and pass it to a user control?
  9.         // UserControlPlayAnimal playAnimals = new UserControlPlayAnimal();
  10.     }  
  11. }  
 

Answers (3)