Reputation: 3448
I am working on a Windows Forms application and I have a DataGrid
for which I am trying to increase the height of the column headers.
I know how its done for a datagridview but I am unsure about the DataGrid
.
I have a column named Actual \n Qty
, and this is being displayed as below:
May I know a way we could increase column header height?
Upvotes: 3
Views: 6510
Reputation: 125312
Height of the column header in DataGrid is calculated based on HeaderFont
property and is stored in a private filed headerFontHeight
. You can get the field using reflection and change its value this way:
var p = typeof(DataGrid).GetField("headerFontHeight",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
p.SetValue(dataGrid1, dataGrid1.HeaderFont.Height * 2);
var m = typeof(DataGrid).GetMethod("OnLayout",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
m.Invoke(dataGrid1, new object[] { null });
dataGrid1.Invalidate();
You can assign the height which you think is enough or you can calculate the height of text of all columns and set the field to the maximum value.
Upvotes: 3