I've tried ...
| grd.GridElement.TableHeaderHeight = 100; |
| ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition(); |
| view.ColumnGroups.Add(new GridViewColumnGroup("Vendor")); |
| view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow()); |
| view.ColumnGroups[0].Rows[0].Height = 100; |
My heading text also has newlines in it (E.g. "Profit\nMargin")
15 Answers, 1 is accepted
Thank you for writing. Currently the Height property of GridViewColumnGroupRow is ignored. You can use the RowSpan property of GridViewColumn instead. Here is sample code:
| view.ColumnGroups[0].Rows[0].Columns[0].RowSpan = 100; |
The TableHeaderHeight is not used when using the ColumnGroupsViewDefinition. We plan to improve our API and address the issues in one of our upcoming releases this year.
Do not hesitate to write me back if you have more questions.
Regards,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
In column groups view mode, the height of the column headers row is synchronized with the height of all other rows. We will consider changing this behavior in one of our upcoming releases in order to enable the requested functionality.
You should iterate through all rows and set their height manually to work around the issue. Take a look at this code:
| foreach (GridViewDataRowInfo row in this.radGridView1.Rows) |
| { |
| row.Height = 20; |
| } |
Do not hesitate to write us if you need further assistance.
All the best,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I have the same problem. I'm using version 2010_03_10_1109. I used the work around that you posted but it takes a while for the form to load. Has there been any changes for this in the newer versions?
Thanks
Celeste
Try wrapping Jack's solution using
radGridView1.BeginUpdate();// do something
radGridView1.EndUpdate();// or using (radGridView1.DeferRefresh()){// do something}Thus preventing the grid from refreshing on each row height change.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
Besides the solutions that Emanuel suggested you can initialize the MinHeight property when handling the CreateRowInfo event which we added in Q3 2010. Consider the code snippet below:
this.radGridView1.MasterTemplate.CreateRowInfo += new GridViewCreateRowInfoEventHandler(MasterTemplate_CreateRowInfo);void MasterTemplate_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e){ e.RowInfo.SuspendPropertyNotifications(); e.RowInfo.MinHeight = 25; e.RowInfo.ResumePropertyNotifications();}I hope this helps.
Greetings,
Jack
the Telerik team
Hi,
Has there been any update on this issue in the past 7 years - setting the height of the column headers when using ColumnGroupsViewDefinitions?
Thanks,
John
You can manipulate the height of the column group headers by setting the RowSpan property. Here is a sample code snippet which result is illustrated in the below screenshot. The Details group is 100 px high and the Address group is 50 px high.
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact"));view.ColumnGroups.Add(new GridViewColumnGroup("Details"));view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address"));view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact"));view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());view.ColumnGroups[0].Rows[0].ColumnNames.Add("CompanyName");view.ColumnGroups[0].Rows[0].ColumnNames.Add("ContactName");view.ColumnGroups[0].Rows[0].ColumnNames.Add("ContactTitle");view.ColumnGroups[1].Groups[0].Rows.Add(new GridViewColumnGroupRow());view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add("Address");view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add("City");view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add("Country");view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow());view.ColumnGroups[1].Groups[1].Rows[0].ColumnNames.Add("Phone");view.ColumnGroups[1].Groups[1].Rows[0].ColumnNames.Add("Fax");view.ColumnGroups[1].RowSpan = 100;view.ColumnGroups[1].Groups[0].RowSpan = 50;radGridView1.ViewDefinition = view;I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
Hi Dess,
How can I change the height of the Row, where all the column names are displayed (Company Name, Address, etc.).
Thanks,
John
In order to change the height of the header row you can specify the MinHeight property of the respective GridViewColumnGroupRow in the GridViewColumnGroup:
view.ColumnGroups[0].Rows[0].MinHeight = 30;radGridView1.ViewDefinition = view;I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
I only want to increase the height of the header row and not the data rows.
How do I do that?
BR
Gillis
Hi Gillis,
I have already answered your question in the private ticket log from your account. I am also posting it here so that the community can take advantage of it.
To set a specific height of the header column group row, you can use the following code:
public Form1()
{
InitializeComponent();
var view = this.radGridView1.ViewDefinition as ColumnGroupsViewDefinition;
view.ColumnGroups[1].RowSpan = 100;
}Here is the result on my side:
You can share if it is working for you.
Hello,
Setting a value to RowSpan property is not working if grid AutoRowSize = true. Any solution?
When the AutoRowSize property is set to true, the rows in RadGridView are sized according to the content they have. That is why properties that affect the row's height are not respected in this case.
I hope this information helps. If you have any additional questions, please let me know.
Dess
Progress Telerik
Hello Dess,
So, in order to set RowSpan manually, I have to set AutoRowSize property to false. But then, how to calculate the height of the data rows where two or more lines of text?
You can iterate all columns in RadGridView and set the GridViewColumn.WrapText property to true. Thus, the cell values will be wrapped. In addition, you can use the demonstrated approach in the following help article showing how to autosize the entire row by measuring the content. For this purpose it is necessary to create a custom GridDataRowElement: https://docs.telerik.com/devtools/winforms/gridview/rows/how-to/autosize-entire-row
As a result, you will have the desired minimum height for the headers in the ColumnGroupsViewDefinition and autosize the data rows as it is illustrated in the screenshot.
Here is a complete code snippet:
public RadForm1(){ InitializeComponent(); this.radGridView1.CreateRow += radGridView1_CreateRow; foreach (GridViewColumn col in this.radGridView1.Columns) { col.WrapText = true; }}private void radGridView1_CreateRow(object sender, GridViewCreateRowEventArgs e){ if (e.RowType == typeof(GridDataRowElement)) { e.RowType = typeof(CustomRowElement); }}private void RadForm1_Load(object sender, EventArgs e){ this.customersTableAdapter.Fill(this.nwindDataSet.Customers); ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition(); view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact")); view.ColumnGroups.Add(new GridViewColumnGroup("Details")); view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address")); view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact")); view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow()); view.ColumnGroups[0].Rows[0].ColumnNames.Add("CompanyName"); view.ColumnGroups[0].Rows[0].ColumnNames.Add("ContactName"); view.ColumnGroups[0].Rows[0].ColumnNames.Add("ContactTitle"); view.ColumnGroups[1].Groups[0].Rows.Add(new GridViewColumnGroupRow()); view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add("Address"); view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add("City"); view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add("Country"); view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow()); view.ColumnGroups[1].Groups[1].Rows[0].ColumnNames.Add("Phone"); view.ColumnGroups[1].Groups[1].Rows[0].ColumnNames.Add("Fax"); view.ColumnGroups[1].RowSpan = 100; view.ColumnGroups[1].Groups[0].RowSpan = 50; view.ColumnGroups[0].Rows[0].MinHeight = 30; radGridView1.ViewDefinition = view; }public class CustomRowElement : GridDataRowElement{ protected override Type ThemeEffectiveType { get { return typeof(GridDataRowElement); } } protected override SizeF MeasureOverride(SizeF availableSize) { SizeF baseSize = base.MeasureOverride(availableSize); CellElementProvider provider = new CellElementProvider(this.TableElement); SizeF desiredSize = SizeF.Empty; foreach (GridViewColumn column in this.ViewTemplate.Columns) { if (!this.IsColumnVisible(column)) { continue; } GridDataCellElement cellElement = provider.GetElement(column, this) as GridDataCellElement; this.Children.Add(cellElement); if (cellElement != null) { cellElement.Measure(new SizeF(column.Width, float.PositiveInfinity)); if (desiredSize.Height < cellElement.DesiredSize.Height) { desiredSize.Height = cellElement.DesiredSize.Height; } } cellElement.Detach(); this.Children.Remove(cellElement); } SizeF elementSize = this.TableElement.RowScroller.ElementProvider.GetElementSize(this.RowInfo); int oldHeight = RowInfo.Height == -1 ? (int)elementSize.Height : RowInfo.Height; this.RowInfo.SuspendPropertyNotifications(); this.RowInfo.Height = (int)desiredSize.Height; this.RowInfo.ResumePropertyNotifications(); if (!this.RowInfo.IsPinned) { int delta = RowInfo.Height - oldHeight; TableElement.RowScroller.UpdateScrollRange(TableElement.RowScroller.Scrollbar.Maximum + delta, false); } baseSize.Height = this.RowInfo.Height; return baseSize; } private bool IsColumnVisible(GridViewColumn column) { return column.IsVisible; }}I hope this information helps. If you have any additional questions, please let me know.
Progress Telerik
