I have a DataGridView on a winform. I am dynamically adding DatagridViewButtonColumn in the load method of form with button name as btnAction and text displayed on it as “Process”.
So, every row in the grid would have this Process button in the last column.
On click event of this button, I am using a BackgroundWorker to call a method which does some calculations. Once the calculations are over, I need to update that clicked button’s text as “Processed” in that row in the grid. How do I achieve this please?
Thanks.
You can set the Value of the cell in question and this will update the text.
For this to work you must have also set the
UseColumnTextForButtonValueproperty of the column to false;With that code you just need to change the column and row indexes to match your cell, or access the cell in some other way.
This code sets your value but as you said you are doing this in a background worker you will need a little bit more code to set the text.
The backgroundworker has an event
RunWorkerCompletedwhich gets fired once the worker has completed. In your workerDoWorkevent handler just have your processing code:Then in your RunWorkerCompleted handler you have the setting of the value: