Question

As described in this question it appears the minimum row height for a row in a DataGridView (WinForm not WPF) is 17 if you wish to display check boxes in a DataGridViewCheckBoxCell. Any smaller and the check box simply disappears!

Is there a way to place a smaller checkbox in a DataGridView cell?

Was it helpful?

Solution

If you are now using .NET 4.0, you can use the DataGridView.RowTemplate to adjust the minimum height.

For example,

DataGridViewRow row = this.dataGridView1.RowTemplate;
row.DefaultCellStyle.BackColor = Color.Bisque;
row.Height = 35;
row.MinimumHeight = 20;

However, as evidenced by this MSDN answer the minimum height for a row with check boxes is 17 pixels. It does not appear there is any way around this problem.

OTHER TIPS

Indeed, you will have to draw the control yourself. On the plus side... drawing the control yourself isn't actually that hard. This is a decent example of drawing your own checkbox (we're using something rather similar in our own code).

Just, instead of overriding it to look disabled, you want to override it to make the box smaller... I don't see any way of calling CheckBoxRenderer.DrawCheckBox with a size, but there shouldn't be anything stopping you from drawing into your own graphics object, shrinking it yourself, then drawing the image you just shrunk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top