I have a DataGridView
which was the subject of a previous question (link). But sometimes the Button is null
. This is fine. But if it is null, is th
Based on Tobias' answer I made a small static helper method to hide the contents of the cell by adjusting it's padding.
Be aware though that the button is still "clickable" in that if the user selects the cell and presses space it clicks the hidden button, so I check that the cell's value is not readonly before I process any clicks in my contentclick event
public static void DataGridViewCellVisibility(DataGridViewCell cell, bool visible)
{
cell.Style = visible ?
new DataGridViewCellStyle { Padding = new Padding(0, 0, 0, 0) } :
new DataGridViewCellStyle { Padding = new Padding(cell.OwningColumn.Width, 0, 0, 0) };
cell.ReadOnly = !visible;
}