How to pass datagridviewbuttoncolumn-click generated value to another Datagridview column

dualshck012

Active member
Joined
Jan 14, 2018
Messages
29
Location
Leyte, Philippines
Programming Experience
1-3
So i have a datagridview that has a button named "generate" to generate a random combination number next to the button column, My problem now is to pass the random number generated by the button to the column Assignment Key. The sample image below shows my wanted output.

1628576461367.png
 
You should be handling the CellContentClick event. The event handler will give you the column index and the row index. You confirm that it's the button column using the column index and then you use the row index to get the row. Once you have the row, you can modify any cell in that row.
 
E.g.
C#:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex == 1)
    {
        var row = dataGridView1.Rows[e.RowIndex];

        row.Cells[2].Value = "Hello World";
    }
}
 
Back
Top Bottom