using System; using System.Data; using System.Web.UI.WebControls; using Infragistics.WebUI.UltraWebGrid; namespace InfragisticsGridControls { public class FixedHierarchical : WebControl { private DataSet ds; private UltraWebGrid _uwg; protected override void CreateChildControls() { base.CreateChildControls(); _uwg = new UltraWebGrid("attachmentGrid"); Controls.Add(_uwg); _uwg.DisplayLayout.ViewType = ViewType.Hierarchical; _uwg.InitializeLayout += new InitializeLayoutEventHandler(InitializeLayout); _uwg.DataBinding += new EventHandler(_uwg_DataBinding); } void InitializeLayout(object sender, LayoutEventArgs e) { _uwg.DisplayLayout.TableLayout = TableLayout.Fixed; // This works, but if the screen region is smaller than the amount, it forces scrolling. //_uwg.Bands[0].Columns.FromKey("FUNCTION_CODE").Width = Unit.Pixel(900); // This doesn't work if the TableLayout = Fixed. //_uwg.Bands[0].Columns.FromKey("FUNCTION_CODE").Width = Unit.Percentage(100); _uwg.DisplayLayout.RowHeightDefault = Unit.Pixel(20); _uwg.Bands[0].ColHeadersVisible = Infragistics.WebUI.UltraWebGrid.ShowMarginInfo.No; UltraGridBand attachBand = new UltraGridBand(); _uwg.Bands.Add(attachBand); } void _uwg_DataBinding(object sender, EventArgs e) { ds = new DataSet(); DataTable table = new DataTable("FSDOC"); table.Columns.Add("FUNCTION_CODE", typeof(string)); table.Constraints.Add("Key", table.Columns["FUNCTION_CODE"], true); ds.Tables.Add(table); DataTable attachTable = new DataTable("FSITEMATTACH"); attachTable.Columns.Add("FUNCTION_CODE", typeof(string)); attachTable.Columns.Add("FILE_NAME", typeof(string)); attachTable.Columns.Add("DESCRIPTION", typeof(string)); attachTable.Columns.Add("USER_CODE", typeof(string)); attachTable.Constraints.Add("Key2", new DataColumn[] { attachTable.Columns["FUNCTION_CODE"], attachTable.Columns["FILE_NAME"] }, true); ds.Tables.Add(attachTable); for (int i = 0; i < 2; i++) { DataRow dr = table.NewRow(); dr["FUNCTION_CODE"] = "FCODE" + i.ToString(); table.Rows.Add(dr); for (int j = 0; j <= i; j++) { DataRow adr = attachTable.NewRow(); adr["FUNCTION_CODE"] = dr["FUNCTION_CODE"]; adr["FILE_NAME"] = @"c:\picture\pretty" + j.ToString() + ".jpg"; adr["DESCRIPTION"] = "This is a description at the child level"; attachTable.Rows.Add(adr); } } ds.Relations.Add(new DataRelation("PARENT", table.Columns["FUNCTION_CODE"], attachTable.Columns["FUNCTION_CODE"])); _uwg.DataSource = ds; } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); _uwg.DataBind(); } } }