sometimes I want to hide buttons in a DataGridViewButtonColumn

后端 未结 9 1121
清歌不尽
清歌不尽 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:21

    Handle custom painting and paint a textbox over there.

    void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
        if (e.ColumnIndex == yourColumnIndex && String.IsNullOrEmpty((string)e.FormattedValue))
        {
            Graphics g = e.Graphics;
            TextBoxRenderer.DrawTextBox(g, e.CellBounds,
                System.Windows.Forms.VisualStyles.TextBoxState.Normal);
            e.Handled = true;
        }
    }
    

提交回复
热议问题