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
1075
Problem with combination of groupLayout, hidden column and autoresize
posted

I've noticed a problem in a specific case of grid layout. When using GroupLayout for RowLayoutStyle, I have column headers spanning over subcolumn headers. When hiding a subcolumns, the autoresize doesn't work like it should anymore. The visible subcolumns are to small, and there is an empty space where the hidden subcolumn would be (if it wasn't hidden). I've added sample code below. You only have to create a form 'Form1', and add an UltraGrid to it.


    public Form1() {
      InitializeComponent();

      var ultraDataSource1 = new Infragistics.Win.UltraWinDataSource.UltraDataSource();
      ultraDataSource1.Band.Columns.Add("Col1");
      ultraDataSource1.Band.Columns.Add("Col2");
      ultraGrid1.InitializeLayout += ultraGrid1_InitializeLayout;
      ultraGrid1.DataSource = ultraDataSource1;
    }

    private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) {
      e.Layout.Bands[0].RowLayoutStyle = Infragistics.Win.UltraWinGrid.RowLayoutStyle.GroupLayout;

      var column = e.Layout.Bands[0].Columns.Add("Header");

      // Add group header
      column.RowLayoutColumnInfo.LabelPosition = Infragistics.Win.UltraWinGrid.LabelPosition.LabelOnly;
      column.RowLayoutColumnInfo.OriginX = 0;
      column.RowLayoutColumnInfo.OriginY = 0;
      column.RowLayoutColumnInfo.SpanX = 2;
      column.RowLayoutColumnInfo.SpanY = 1;

      // Set column 1 on the second row
      column = e.Layout.Bands[0].Columns["Col1"];
      column.RowLayoutColumnInfo.OriginX = 0;
      column.RowLayoutColumnInfo.OriginY = 1;
      column.RowLayoutColumnInfo.SpanX = 1;
      column.RowLayoutColumnInfo.SpanY = 1;

      // Set column 2 on the second row
      column = e.Layout.Bands[0].Columns["Col2"];
      column.RowLayoutColumnInfo.OriginX = 1;
      column.RowLayoutColumnInfo.OriginY = 1;
      column.RowLayoutColumnInfo.SpanX = 1;
      column.RowLayoutColumnInfo.SpanY = 1;
      column.Hidden = true;

      // AutoResize makes room for column 2. Comment the line below to see the difference.
      ultraGrid1.DisplayLayout.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows);
    }

Obviously I could use the groups collection on the band in this case, but our business application contains multiple row headers. We need to autoresize the columns based on the data. Is this a bug, or am I doing something wrong? Thanks in advance.

Edit > I am using UltraGrid v10.1.20101.1007 btw.

  • 469350
    Verified Answer
    Offline posted

    Hi,

    This is not a bug. The code you have here doesn't really make sense.

    You have set your RowLayoutStyle to GroupLayout. This allows you to create groups in the grid and place columns (or other groups) inside those groups. But the code you have here is not creating any groups. You are using a column as a group header. This is what we used to tell people to do in order to simulate groups before we had a GroupLayout style, but it's not really a great way to do this.

    The reason the AutoSize doesn't seem to work right in this case is that your group header column has a SpanX of 2 and the columns each have a SpanX of 1. Since there is no actual Group, there's no connection between the group header and the column headers, so there's no reason for the grid to keep them in synch.

    To do this correctly with a real group, you would do something like this:


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                e.Layout.Bands[0].RowLayoutStyle = Infragistics.Win.UltraWinGrid.RowLayoutStyle.GroupLayout;

                // Add group header
                UltraGridGroup group = e.Layout.Bands[0].Groups.Add();           
                group.RowLayoutGroupInfo.OriginX = 0;
                group.RowLayoutGroupInfo.OriginY = 0;
                group.RowLayoutGroupInfo.SpanX = 2;
                group.RowLayoutGroupInfo.SpanY = 1;

                UltraGridColumn column;

                // Set column 1 on the second row
                column = e.Layout.Bands[0].Columns["Col1"];
                column.RowLayoutColumnInfo.OriginX = 0;
                column.RowLayoutColumnInfo.OriginY = 0;
                column.RowLayoutColumnInfo.SpanX = 1;
                column.RowLayoutColumnInfo.SpanY = 1;
                column.RowLayoutColumnInfo.ParentGroup = group;

                // Set column 2 on the second row
                column = e.Layout.Bands[0].Columns["Col2"];
                column.RowLayoutColumnInfo.OriginX = 1;
                column.RowLayoutColumnInfo.OriginY = 0;
                column.RowLayoutColumnInfo.SpanX = 1;
                column.RowLayoutColumnInfo.SpanY = 1;
                column.RowLayoutColumnInfo.ParentGroup = group;
                column.Hidden = true;

                // AutoResize makes room for column 2. Comment the line below to see the difference.
                ultraGrid1.DisplayLayout.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows);
            }