You might be wondering what I?m doing with winforms, recently in one of my internal project I had to use winforms for some tooling. I used the data grid that came out of the box which contained a button column. In data grid, its not actually a button, its just painted to look like a button. So, if you want to do some normal button activities like setting the visibility, enabling/disabling etc its not trivial task (I couldn?t find anything simple).
I just managed to crack this code, which basically hides the button based on the condition. In my case if the one of other column value is less than 1 I need to hide the button.
The code is simple to follow, here are the high level steps
1. Attach the cell painting event handler to grid view
2. Check if the current painting column is the button column
3. Get the value from the other column, based on which you need to hide the button.
4. I?m simply drawing the grid lines and erasing the content.