Hello,
I have problem to arrange the group headers for my grid and print them I like. The grid has 2 bands. Each band has 1 column with deparment name (band0) or employee name (band1) followed by 1 columns for every day within a date range up to 1 year.
After a first group for placeholder for the department column I like to have 3 header groups: a month-group over all columns in the same month. a week-numer-group within the month-group and a dayOfWeek-group within the month-group (see attached picture).
But as you can see (attached pic) my groups have different width and are not aligned to the month-group.
My code snipped looks as follows:
CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture;UltraGridGroup groupMonth = null;UltraGridGroup groupWeekNum = null;UltraGridGroup groupWeekDay = null;try { // enable label sizing band0.Layout.Override.AllowRowLayoutLabelSizing = RowLayoutSizing.Both; // department group UltraGridGroup groupOrg = band0.Groups.Add( "GroupOrg" ); groupOrg.Header.Caption = " "; groupOrg.Hidden = false; groupOrg.RowLayoutGroupInfo.OriginX = 0; groupOrg.RowLayoutGroupInfo.OriginY = 0; groupOrg.RowLayoutGroupInfo.SpanX = 1; groupOrg.RowLayoutGroupInfo.SpanY = 6; // department column UltraGridColumn col = band0.Columns[FormPlanning.KeyCol_Organisation]; col.RowLayoutColumnInfo.OriginX = 0; col.RowLayoutColumnInfo.OriginY = 0; col.RowLayoutColumnInfo.SpanX = 1; col.RowLayoutColumnInfo.SpanY = 6; col.RowLayoutColumnInfo.ParentGroup = groupOrg; // col counter for date columns int dayCount = 1; for ( DateTime date = this.servicePlan.OpenInfo.OpenRange.From; date <= this.servicePlan.OpenInfo.OpenRange.To; date = date.AddDays( 1 ) ) { string colKey = date.ToShortDateString(); // month-group string key = string.Format( "GroupMonth{0}", date.Month ); if ( !band0.Groups.Exists( key ) ) { DateTime endOfMOnth = new DateTime( date.Year, date.Month, DateTime.DaysInMonth( date.Year, date.Month ) ); groupMonth = band0.Groups.Add( key ); groupMonth.Header.Caption = cultureInfo.DateTimeFormat.MonthNames[date.Month-1]; groupMonth.RowLayoutGroupInfo.OriginX = dayCount; groupMonth.RowLayoutGroupInfo.OriginY = 0; groupMonth.RowLayoutGroupInfo.SpanX = this.servicePlan.OpenInfo.OpenRange.Contains( endOfMOnth ) ? DateTime.DaysInMonth( date.Year, date.Month ) : this.servicePlan.OpenInfo.OpenRange.To.Day; groupMonth.RowLayoutGroupInfo.SpanY = 6; } // week of year group if ( date.DayOfWeek == cultureInfo.DateTimeFormat.FirstDayOfWeek ) { int weekOfYear = cultureInfo.DateTimeFormat.Calendar.GetWeekOfYear( date, cultureInfo.DateTimeFormat.CalendarWeekRule, cultureInfo.DateTimeFormat.FirstDayOfWeek ); int weekSpanX = this.servicePlan.OpenInfo.OpenRange.Contains( date.AddDays( 6 ) ) ? 7 : ( this.servicePlan.OpenInfo.OpenRange.To.Date - date.Date ).Days; key = string.Format( "GroupWeekNum{0}", weekOfYear ); if ( !band0.Groups.Exists( key ) ) { // -> week number groupWeekNum = band0.Groups.Add( key ); groupWeekNum.Header.Caption = weekOfYear.ToString(); groupWeekNum.RowLayoutGroupInfo.OriginX = dayCount; groupWeekNum.RowLayoutGroupInfo.OriginY = 2; groupWeekNum.RowLayoutGroupInfo.SpanX = weekSpanX; groupWeekNum.RowLayoutGroupInfo.SpanY = 2; groupWeekNum.RowLayoutGroupInfo.ParentGroup = groupMonth; // -> day of month for week number groupWeekDay = band0.Groups.Add( string.Format( "GroupWeekDay{0}", weekOfYear ) ); groupWeekDay.Header.Caption = date.Day.ToString(); groupWeekDay.RowLayoutGroupInfo.OriginX = dayCount; groupWeekDay.RowLayoutGroupInfo.OriginY = 4; groupWeekDay.RowLayoutGroupInfo.SpanX = weekSpanX; groupWeekDay.RowLayoutGroupInfo.SpanY = 2; groupWeekDay.RowLayoutGroupInfo.ParentGroup = groupMonth; } } // assign Band 0 column col = band0.Columns[colKey]; col.Width = printOptions.FitToColWidth; col.MinWidth = printOptions.FitToColWidth; col.RowLayoutColumnInfo.ParentGroup = groupWeekNum; // assign Band 1 column col = band1.Columns[colKey]; col.Width = printOptions.FitToColWidth; col.MinWidth = printOptions.FitToColWidth; col.RowLayoutColumnInfo.ParentGroup = groupWeekNum; dayCount++; } // disable label sizing band0.Layout.Override.AllowRowLayoutLabelSizing = RowLayoutSizing.None; } catch ( Exception x ) { Logger.Error( x, false ); }
Thank you for any help.
Regards
Markus
Hi Mac,
Have you tried using the Row Layout with Groups designer? Please take a look at the following help topic to see how you can set this up at design time:http://help.infragistics.com/doc/WinForms/2015.2/CLR4.0/?page=WinGrid_Grouping_Columns_in_Row_Layout_Mode_using_the_Designer.html
I recommend using the designer if possible. If not, I have put together a sample that shows how you could set this up in code. Please note that the code in the sample has been simplified to better demonstrate the use of RowLayouts.
Please let me know if you have any further questions.
Hello Mike,
Thank you for the sample, it looks easy, but why you set "groupDay1.RowLayoutGroupInfo.SpanX = 11;". This value is greather than the number of columns belongigng to this group?
I can not use the designer, I have to build up all from code in this scenario, there is even no form where the grid is displayed before printing.
My group headers looks better now (see attached picture), but for my scenario I still have some questions:
1) I have add the grid to the preview-dialog controls (hidden). If I just use the grid created from code, grid initialize events are not fired. Do you have a better solution for this scenario?
2) Why I have to specify OriginX, OrigiginY, SpanX, SpanY for the group AND for the organisation-column? If I don't set these values the 'january' header starts left above the organisation-column. I don't have to set these values for Band 1 column, In your sample you don't have to set these values.
// Group Organisation UltraGridGroup groupOrg = band0.Groups.Add( "GroupOrg" ); groupOrg.Header.Caption = string.Empty; groupOrg.RowLayoutGroupInfo.OriginX = 0; groupOrg.RowLayoutGroupInfo.OriginY = 0; groupOrg.RowLayoutGroupInfo.SpanX = 1; groupOrg.RowLayoutGroupInfo.SpanY = 6; // Column Organisation UltraGridColumn col0 = band0.Columns[FormPlanning.KeyCol_Organisation]; col0.Width = FormPlanning.ColWidthOrganisation; col0.RowLayoutColumnInfo.OriginX = 0; col0.RowLayoutColumnInfo.OriginY = 0; col0.RowLayoutColumnInfo.SpanX = 1; col0.RowLayoutColumnInfo.SpanY = 6; col0.RowLayoutColumnInfo.ParentGroup = groupOrg; UltraGridColumn col1 = band1.Columns[FormPlanning.KeyCol_Organisation]; col1.Width = FormPlanning.ColWidthOrganisation; col1.RowLayoutColumnInfo.ParentGroup = groupOrg;
3) The last column in Band 0 has bigger width. I can not find the reason for that. Any ideas?
4) I like to have 3 header lines for the organisation-column to describe the header content (month, week-numbers, month-day). How I have to add two more lines to the OrgGroup?
I have attached my current layout and a complet code snipped of Initialize_Layout.
Thank you for your help.
Best regards