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
I have fixed it: I did not set the Indentation = 0 for the root band, just for the child band. In another grid without GroupLayout, this was not necessary.
This problem was also discussed here: http://es.infragistics.com/community/forums/t/69377.aspx
Everything works fine now.
we have evaluated the control type far ago for our employee scheduling task view. And this we talking about hereshould be a printout in compact layout to show yearly planned vacations and something like this, without opening the schedule view before.
But I have found a solution. I have modified your sample und attached it to this post. For me, the key for having overlapping week-groups was NOT to define the parent-group for the week-groups. All groups are just arranged by the coordinates and all columns are added to their month-group, not to the week-group.
In my work project I have one last problem, you maybe can give me a tip: On the left side of the grid (left to the employee names) you see some emty space. This space belongs to the grid, because if I set some grid back color, the color of this space changes. If I turn row selectors on, the empty space remains (see attached picture).
I could not figure out where is this coming from. Remeber: I add the grid to the preview-dlg controls container as hidden component, because I don't have a hosting form. Otherwise nothing is printed to the preview. Has this any (bad) influence?
Hi Markus,
I just wanted to let you know that I am actively looking into this. I tried solving the overlapping issue, and was not able to come up with a good solution -- a group is not intended to span multiple parent groups.
RowLayouts are not normally configured in code. Although the properties are exposed, the intention is for the work to be done in the designer.
Are you able to use a control other than the grid for this project? I believe that the spreadsheet, schedule, or ganttview might be a better control to display data in this way. Please look into these controls and let me know your thoughts.
Hello again,
I still having some problems arranging the header groups. I guess I have figured out what the problem could be. If the week-groups overlapping the month borders, and week-groups and columns both have the current month-group as parent, it leads to some visually disalignement at the end of 'march' (see attached pic). The disalignement are two columns, one overlapping week 5 and one averlapping week 9.
In your sample you dont't solve this problem, because you just have used one month and you have cut the weeks.
Do you have a solution for this problem?
I have tried define one more header-group, which spans overall other groups and acts as parent-group for all others. But I could not assign the columns in a way that all groups are sized ok. What is about this approach?
Regards, Markus
I have done some work on the layout and so on. Visually I have two last problem. First: The last column of the last week (see attached picture) is somewhat streched for group headers and band 0 columns. Band 1 columns are not. Second: There is some empty space on the left of the grid. I could not found the reason for this. This area is affected by the grid.appearance.backcolor. I use the print document with defaults, ecept border.
Conceptually I'm not sure if I'm using the group headers correctly. If I have two bands, do I need to define the header groups for every band and assigning the band0-columns to the band0-groups and the band1-columns to the band1-groups.
If I just set properties as in your sample, my grid looks complete "unaligned". In the documentation I could not find a more complex sample with multiband and multirow-header.