Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
4032
Printing Multiband WinGrid with GroupLayout style
posted

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

groupheaderslayout.zip
Parents
No Data
Reply
  • 12480
    Offline posted

    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.

    GroupHeaderArrangement.zip
Children