sometimes I want to hide buttons in a DataGridViewButtonColumn

后端 未结 9 1109
清歌不尽
清歌不尽 2020-12-20 15:50

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

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 16:08

    As an improvement to Sriram's answer, I would suggest just overriding the cell painting event and only painting the background. I found that painting a textbox made it look a little odd.

    void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == yourColumnIndex && String.IsNullOrEmpty((string)e.FormattedValue)) { e.PaintBackground(e.ClipBounds, true); e.Handled = true; } }

提交回复
热议问题