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

GridView Hierarchy with two childTableDefinitions.

3 Answers 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gureumi
Top achievements
Rank 1
gureumi asked on 11 Feb 2010, 07:11 PM
I have a GridView hierarchy with two child tables, of which I want to show only a few chosen columns .

In Q2, it worked fine with the following code.
 

 

GridViewTableDefinition tdPayment = new GridViewTableDefinition();  
GridViewTableDefinition tdDetail = new GridViewTableDefinition();  
 
tdPayment.DataSource = MySalePayments = GetSalePaymentsData();  
tdPayment.AutoGenerateFieldDescriptors = false;  
 
TableRelation tr = new TableRelation();  
tr.FieldNames.Add(new FieldDescriptorNamePair("Receipt""Receipt"));  
tdPayment.Relation = tr;  
 
GridViewDataColumn paymentType = new GridViewDataColumn();  
paymentType.UniqueName = "SalePaymentType";  
paymentType.Header = "PaymentType";  
paymentType.DataType = typeof(short);  
GridViewDataColumn amount = new GridViewDataColumn();  
amount.UniqueName = "Amount";  
amount.Header = "Amount";  
amount.DataType = typeof(decimal);  
 
tdPayment.FieldDescriptors.Add(paymentType);  
tdPayment.FieldDescriptors.Add(amount);  
           
tdDetail.AutoGenerateFieldDescriptors = false;           
tdDetail.DataSource = MySaleDetails = GetSaleDetailData();  
 
tdDetail.Relation = tr;  
GridViewDataColumn itemId = new GridViewDataColumn();  
itemId.UniqueName = "ItemId";  
itemId.Header = "ItemId";  
itemId.DataType = typeof(string);  
GridViewDataColumn saleQty = new GridViewDataColumn();  
saleQty.UniqueName = "SaleQuantity";  
saleQty.Header = "Sale Qty";  
saleQty.DataType = typeof(short);  
GridViewDataColumn unitPrice = new GridViewDataColumn();  
unitPrice.UniqueName = "UnitPrice";  
unitPrice.Header = "Price";  
unitPrice.DataType = typeof(decimal);  
GridViewDataColumn discount = new GridViewDataColumn();  
discount.UniqueName = "Discount";  
discount.Header = "Discount";  
discount.DataType = typeof(decimal);  
GridViewDataColumn individualDiscount = new GridViewDataColumn();  
individualDiscount.UniqueName = "IndividualDiscount";  
individualDiscount.Header = "Ind.Discount";  
individualDiscount.DataType = typeof(decimal);  
 
tdDetail.FieldDescriptors.Add(itemId);  
tdDetail.FieldDescriptors.Add(saleQty);  
tdDetail.FieldDescriptors.Add(unitPrice);  
tdDetail.FieldDescriptors.Add(discount);  
tdDetail.FieldDescriptors.Add(individualDiscount);  
 
radGridViewSalesList.TableDefinition.ChildTableDefinitions.Add(tdPayment);  
radGridViewSalesList.TableDefinition.ChildTableDefinitions.Add(tdDetail);  
 

 

When Run in Q3, AutoGenerateFieldDescriptors was simply ignored showing all columns.

In Q3, it was suggested that I use AutoGenerateColumns of GridViewDataControl .
I was able to do it with single child table using DataLoading handler as shown in the demo source code.
But I don't know how to do it with two child tables.

3 Answers, 1 is accepted

Sort by
0
gureumi
Top achievements
Rank 1
answered on 11 Feb 2010, 11:42 PM

Problem seems to me is that we can not set visual tree more than once under RadGridView.HierarchyChildTemplate

I also wonder how I can use GridViewDataControl in the context of two child tables.
My understanding is that sender is RadGridView object in the following code.

private void RadGridView1_DataLoading(object sender,   
                                      GridViewDataLoadingEventArgs e)  
{  
   GridViewDataControl dataControl = (GridViewDataControl) sender;  
   if (dataControl.ParentRow != null)  
   {  
      dataControl.CanUserFreezeColumns = false;  
      dataControl.ShowGroupPanel = false;  
      dataControl.AutoGenerateColumns = false;  
 
      GridViewDataColumn column = new GridViewDataColumn();  
      column.Header = "Order ID";  
      column.DataMemberBinding = new System.Windows.Data.Binding("OrderID");  
      dataControl.Columns.Add(column);  
      // omitted lines  
   }  
Am I missing something?
0
Stefan Dobrev
Telerik team
answered on 16 Feb 2010, 11:04 AM
Hello gureumi,

I have prepared a small example which illustrates how to distinguish which is the correct grid for the given table definition. Please find it in the attached archived file.

Hope this helps,
Stefan Dobrev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
gureumi
Top achievements
Rank 1
answered on 16 Feb 2010, 11:08 PM
Thanks you.

I got it fixed.
Tags
GridView
Asked by
gureumi
Top achievements
Rank 1
Answers by
gureumi
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or