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
249
Colspan + Column resize
posted

Hi,

I have a grid with resizable columns (either on window size or more commonly content length). Some of my cells need span columns.

I followed this example by IG:

http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7325

This gets your (very!) basic cell-based column spanning - quite frankly I think a ColSpan property should be provided so you needn't do all of this. It is easy enough make it work for more than 2 columns. But now I need to resize my columns. The sample provided fails horribly at this (I just docked the grid and set the columns to auto-size -> uh oh!). Now I can _probably_ recalculate all the spanning column widths on every resize event but that seems like a lot of work.

So the question is: Is there a good solution for this?

Thank you,

Teun Segers

Parents
No Data
Reply
  • 249
    posted

    This seems to work ok for the moment (based on original IG sample):

    public bool BeforeCreateChildElements(UIElement parent)

    {
      //This boolean is a bit weird - does not work as documented. Just don't try to "fix" it.
      bool skipCreation = false; 

      if (parent is CellUIElement)
      {
        var cellUI = (CellUIElement)parent;
        var targetCell = (UltraGridCell)cellUI.GetContext(typeof (UltraGridCell));
        var modelCells = UltraGridHelper.GetCellModels(targetCell.Row);
        var modelCell = modelCells[targetCell.Column.Index]; 

        if (modelCell == null)
        {
          cellUI.Rect = new Rectangle(cellUI.Rect.X, cellUI.Rect.Y, 0, 0);
          skipCreation = true;
        }
        else
        {
          if (modelCell.ColumnSpan > 1)
          {
            var compoundWidth = targetCell.Column.Width;
            compoundWidth += targetCell.Row.Cells[targetCell.Column.Index + 1].Column.Width;
            cellUI.Rect = new Rectangle(cellUI.Rect.X, cellUI.Rect.Y, ++compoundWidth, targetCell.Row.Height);
          }
        }
      } 

      return skipCreation;
    }

    (I tried - at length - to get code to format properly on this forum but it still looks bad... again)

    This may not address all the issues I stated but it may help some people.

    -EDIT 1-

    FYI: UltraGridHelper.GetCellModels(targetCell.Row) looks up the ListObject which has a mark up object in its Tag property. This mark up object is then used to style the cell. It is not a relevant part of this solution but it may help you understand it.

    I removed the "code" tags from the post as they made things even less legible.

Children
No Data