This is a migrated thread and some comments may be shown as answers.

[Solved] programatic creation of hierarchy grid

1 Answer 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gijo
Top achievements
Rank 1
Gijo asked on 20 Nov 2009, 12:58 AM

I am trying to create a hierarchy grid programmatically based on a xml file. I am successful in adding three hierarchies. It seems that there is some problem in the way I added the third hierarchy because the properties (font color, bold) i applied are not showing up in third hierarchy (strangely it shows up in second hierarchy and second hierarchy is created by same code block that created third hierarchy) . Also, when I added the fourth hierarchy it throws error in 'DetailTableDataBind' because it cannot find the datakey values in the third hierarchy.  The code snippet is here.



        public void GenerateGrid(RadGrid radGrid1) 
        {
            //loading xml file
            chartXml = XElement.Load(FilterPath, LoadOptions.PreserveWhitespace); 
            title = chartXml.Attribute("title").Value; 
 
            radGrid1.MasterTableView.PageSize = 10; 
 
            foreach (XElement chartElement in chartXml.Elements()) 
            { 
                if (chartElement.Name.LocalName != null && chartElement.Name.LocalName == "Filters"
                { 
                    if(chartElement.Attribute("referencePath") != null
                        referencePath = chartElement.Attribute("referencePath").Value; 
 
                    bool topFilter = true
 
                    foreach (XElement filterElement in chartElement.Elements()) 
                    { 
                        if (topFilter) 
                        { 
                            radGrid1.MasterTableView.Width = Unit.Percentage(100); 
                            radGrid1.MasterTableView.BorderWidth = 2; 
                            radGrid1.MasterTableView.BorderColor = System.Drawing.Color.Red; 
 
                            if(filterElement.Attribute("name") != null
                                radGrid1.MasterTableView.Name = filterElement.Attribute("name").Value;                           
 
                            if(filterElement.Attribute("dataKeyNames") != null
                                radGrid1.MasterTableView.DataKeyNames = filterElement.Attribute("dataKeyNames").Value.Split(','); 
 
                            string[] columnNames = filterElement.Attribute("columns").Value.ToString().Split(','); 
                            foreach (string columnName in columnNames) 
                            { 
                                GridBoundColumn boundColumn = new GridBoundColumn(); 
                                radGrid1.MasterTableView.Columns.Add(boundColumn); 
                                boundColumn.UniqueName = columnName; 
                                boundColumn.DataField = columnName; 
                                boundColumn.HeaderText = columnName;                                 
                            } 
 
                            lastAddedDetailTable = radGrid1; 
                            topFilter = false
                        } 
                        else 
                        { 
                            GridTableView tableView = new GridTableView(radGrid1); 
 
                            tableView.Width = Unit.Percentage(100);                          
                            tableView.Font.Bold = true
                            tableView.BorderWidth = 2; 
                            tableView.BorderColor = System.Drawing.Color.Red; 
 
                            if (filterElement.Attribute("name") != null
                                tableView.Name = filterElement.Attribute("name").Value; 
 
                            if (filterElement.Attribute("dataKeyNames") != null
                                tableView.DataKeyNames = filterElement.Attribute("dataKeyNames").Value.Split(','); 
 
                            if (lastAddedDetailTable.ID == "RadGrid1"
                            { 
                                radGrid1.MasterTableView.DetailTables.Add(tableView); 
                            } 
                            else 
                            { 
                                ((GridTableView)lastAddedDetailTable).DetailTables.Add(tableView); 
                            } 
 
                            string[] columnNames = filterElement.Attribute("columns").Value.ToString().Split(','); 
 
                            foreach (string columnName in columnNames) 
                            { 
                                GridBoundColumn boundColumn = new GridBoundColumn(); 
                                tableView.Columns.Add(boundColumn); 
                                boundColumn.UniqueName = columnName; 
                                boundColumn.DataField = columnName; 
                                boundColumn.HeaderText = columnName;                                 
                            } 
 
                            lastAddedDetailTable = tableView;                            
                        }                        
                    } 
                }                
            } 
        } 

The sample xml file is this.
<?xml version="1.0" encoding="utf-8" ?> 
<Chart title="Customer Order Details"
    <Filters referencePath="GetCustomerOrders1"
        <Filter name="Customers" dataKeyNames="CustomerId" columns = "CustomerId,CustomerName,CustomerAddres" /> 
        <Filter name="Orders"  dataKeyNames="OrderId" columns = "OrderId,OrderDate,CustomerId" /> 
        <Filter name="OrderDetails" dataKeyNames="ProductId" columns = "ProductId,OrderDetailsId,UnitPrice,ProductName" /> 
        <Filter name="ProductDetails" dataKeyNames="ProductId" columns = "ProductName,ProductDesc,ProductId" /> 
    </Filters> 
</Chart> 


Help appreciated.

Thanks,
Gijo Joseph.

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 25 Nov 2009, 11:42 AM
Hi Gijo,

I reviewed the setup, and it looks correct.
To further track the issue, it will be best if you open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will review it locally, and advise you further.

All the best,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Gijo
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or