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
500
can the dynamic added column used multicolumn header?
posted

 I add some columns in Page_Load,and want to set multicolumn header in these columns.

in Page_load

var dr = db.ExecuteReader("select id,name from tb_warehouse");
                while (dr.Read())
                {
                    var col = new UltraGridColumn(true)
                                  {
                                      BaseColumnName = ("Quantity" + dr["id"]),
                                      Key = ("Quantity" + dr["id"]),
                                      HeaderText = dr["name"].ToString(),
                                      DataType = "System.Decimal",
                                      AllowUpdate = AllowUpdate.Yes,
                                      Format = "###,###,###.##",
                                      Width = Unit.Pixel(60)
                                  };
                    col.CellStyle.HorizontalAlign = HorizontalAlign.Right;
                    j += 1;
                    col.Header.RowLayoutColumnInfo.OriginX = j;
                    uwgList.Columns.Insert(j, col);

                }
                dr.Close();

 

in InitializeLayout
            foreach (UltraGridColumn c in uwgList.DisplayLayout.Bands[0].Columns)
            {
                c.Header.RowLayoutColumnInfo.OriginY = 1;
            }
            var ch = new ColumnHeader(true);
            ch.Caption = "test";
            ch.RowLayoutColumnInfo.OriginX = 4;
            ch.RowLayoutColumnInfo.OriginY = 0;
            ch.RowLayoutColumnInfo.SpanX = uwgList.Columns.FromKey("sumQuantity").Index -
                                           uwgList.Columns.FromKey("unit").Index;
            e.Layout.Bands[0].HeaderLayout.Add(ch);

foreach (UltraGridColumn c in e.Layout.Bands[0].Columns)
            {
                if ((c.Index <= uwgList.Columns.FromKey("unit").Index) ||
                    (c.Index >= uwgList.Columns.FromKey("sumQuantity").Index))

                {
                    c.Header.RowLayoutColumnInfo.OriginY = 0;
                    c.Header.RowLayoutColumnInfo.SpanY = 2;                

}
            }

 

but these columns's header caption didn't display the "test".

why??

Parents
No Data
Reply
  • 28464
    posted

    From what I can tell, the code you are using seems perfectly fine and is in sync with what we have in our multi column example located here:

    http://samples.infragistics.com/2008.2/webfeaturebrowser/srcview.aspx?path=WebGrid/MultiHeaders/MultiHeaders.src&file=MultiHeaders.aspx.cs&font=3

    The only reason for the problem that I can think of at this type is that InitializeLayout happens at an earlier point than Page_Load, hence the columns are still not instantiated there.

    Can you place breakpoint in both methods and see which one gets executed first? Or can you move your column init code from Page_Load to OnInit and see how it goes?

Children