Update button text in datagridview

I have a DataGridView on winform. I dynamically add a DatagridViewButtonColumn to the form load method with the button name as btnAction and the text displayed on it as "Process".

So, each row in the grid will have this "Process" button in the last column.

In the click event of this button, I use BackgroundWorker to call a method that performs some calculations. Upon completion of the calculations, I need to update this text of the pressed "Processed" button on this line in the grid. How do I achieve this?

Thank.

+3
source share
1 answer

You can set the value of the cell in question, and this will lead to an update of the text.

, UseColumnTextForButtonValue false:

dataGridView[0,0].Value = "Processed";

- .

, , , , .

RunWorkerCompleted, . DoWork :

void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    // Some long running processing
}

RunWorkerCompleted :

void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    dataGridView1[0,0].Value = "Processed";
}
+3

All Articles