This is a migrated thread and some comments may be shown as answers.

ColumnGroupsView height

5 Answers 440 Views
GridView
This is a migrated thread and some comments may be shown as answers.
konrad
Top achievements
Rank 1
konrad asked on 23 Jul 2018, 11:28 AM

Sample code below. Just copy, paste and run. :)

var grid = new RadGridView
{
    Dock = DockStyle.Fill,
    AutoSizeRows = false,
    AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
     
};
 
grid.Columns.Add(new GridViewTextBoxColumn() { Name = "column1", HeaderText = "Column 1" });
grid.Columns.Add(new GridViewTextBoxColumn() { Name = "column2", HeaderText = "Column 2" });
grid.Columns.Add(new GridViewTextBoxColumn() { Name = "column3", HeaderText = "Column 3" });
grid.Columns.Add(new GridViewTextBoxColumn() { Name = "column4", HeaderText = "Column 4" });
 
var columnGroupsView = new ColumnGroupsViewDefinition();
columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup("Group 1 Line 1" + Environment.NewLine + "Group 1 Line 2"));
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows.Add(new GridViewColumnGroupRow());
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows[0].ColumnNames.Add("column1");
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows[0].ColumnNames.Add("column2");
 
columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup("Group 2 Line 1" + Environment.NewLine + "Group 2 Line 2"));
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows.Add(new GridViewColumnGroupRow());
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows[0].ColumnNames.Add("column3");
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows[0].ColumnNames.Add("column4");
 
grid.ViewDefinition = columnGroupsView;
 
var form = new RadForm();
form.Controls.Add(grid);
form.ShowDialog();

 

How to change by code height of group row? Please see attached image.

Important: I want to stay with AutoSizeRows = false.

5 Answers, 1 is accepted

Sort by
0
konrad
Top achievements
Rank 1
answered on 23 Jul 2018, 11:40 AM
Also how to change second row height (columns).
0
Dimitar
Telerik team
answered on 24 Jul 2018, 09:38 AM
Hi Dominik,

You need to set the RowSpan and MinHeight properties. Here is an example:
var group = new GridViewColumnGroup("Group 1 Line 1" + Environment.NewLine + "Group 1 Line 2");
group.RowSpan = 50;
columnGroupsView.ColumnGroups.Add(group);
 
var groupRow = new GridViewColumnGroupRow();
groupRow.MinHeight = 50;
 
columnGroupsView.ColumnGroups[columnGroupsView.ColumnGroups.Count - 1].Rows.Add(groupRow);

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
konrad
Top achievements
Rank 1
answered on 25 Jul 2018, 09:42 AM
Setting MinHeight do GridViewColumnGroupRow is working but... this also changed the height od filtering row and data rows (which is not intentional).
0
Accepted
Dimitar
Telerik team
answered on 27 Jul 2018, 07:15 AM
Hi Dominik,

You need to manually set the height of the rows. Here is  the code:
foreach (var item in grid.Rows)
{
   item.Height = 25;
}

Currently, this cannot be done for the new row and it should have the height of the group row.

I hope this will be useful. 

Regards,
Dimitar
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
commented on 02 Mar 2023, 08:53 AM

Sorry, is this solution still the only valid today? I haven't found anything else about it.

Regards

Alessandro

Dinko | Tech Support Engineer
Telerik team
commented on 03 Mar 2023, 01:11 PM

According to the provided information, it seems that you are using ColumnGroupsViewDefinition. The GridViewColumnGroupRow offers the MinHeight property which controls the minimum height of the row. If the property is not set, the row height will be equal to the maximum RowSpan of the columns in that row. On the other hand, the GridViewColumnGroup offers the RowSpan property that controls the vertical span of the group (the height) in pixels.

columnGroupsView.ColumnGroups.Add(new GridViewColumnGroup("Group 1 Line 1" + Environment.NewLine + "Group 1 Line 2") { RowSpan= 100});

You can consider using the RowSpan property.

 

Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
commented on 03 Mar 2023, 01:34 PM

Thanks Dinko,
I was referring to the possibility of sizing the data rows (through rowHeigth and RowSpan) independently from the other rows (headers and more) and in the presence of groups of columns. In my case I resized the rows by looping through each row in the rowschanged event.
Dinko | Tech Support Engineer
Telerik team
commented on 06 Mar 2023, 02:27 PM

What else you can try is to subscribe to the RowFormatting event of the RadGridView which will be called for each data row. You can get the row element from the event arguments and change its height depending on your requirement.

private void RadGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    e.RowElement.RowInfo.Height = 10;
}

Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
commented on 07 Mar 2023, 07:17 AM

thank you Dinko. 
0
konrad
Top achievements
Rank 1
answered on 30 Jul 2018, 08:52 AM

Not the perfect solution but I will use it. :) Thanks!

Tags
GridView
Asked by
konrad
Top achievements
Rank 1
Answers by
konrad
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or