I am working with a C# application that is connecting to a web service in the code behind on a Click event of a button doing a search...say for customers and their orders. The data comes to the app. as XML but is Deserialize into a List<OfAClass>. The parent grid is utilizing one data source (Customers) and the child utilizes another(Orders). I have been looking at samples but do not get how to tie the two grids together. Is this done in the DataLoading event? In the examples the child grid does not seem to get an ItemSource. How do I tell the child grid where to get its data(Orders)? And How do I tie the two datasources together?
Any codes samples would be greatly appreciated.
Thanks ~ Doug
Any codes samples would be greatly appreciated.
Thanks ~ Doug
2 Answers, 1 is accepted
0
Hello Doug,
Vlad
the Telerik team
You can have completely separate data sources for all hierarchy levels. Just define the child grid in HierarchyChildTemplate and assign ItemsSource to desired value. You can create a view model to do this or just use the Loaded event of the child grid.
Regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0

Doug
Top achievements
Rank 1
answered on 11 Nov 2011, 06:32 PM
Sorry...I am new to WPF. I still do not get how the two grids link together with the two different sources. I have the code attached that I have come up with so far. If you could help with the linkage I think that will get me to the finish line.
Thanks ~ Doug
<
Window
x:Class
=
"Customer.CustomerSearch"
Title
=
"Customer Search"
Height
=
"500"
Width
=
"900"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Icon
=
"/Customer%20Search;component/favicon.ico"
ResizeMode
=
"NoResize"
SizeToContent
=
"WidthAndHeight"
mc:Ignorable
=
"d"
xmlns:d
=
"http://schemas.microsoft.com/expression/blend/2008"
d:DesignWidth
=
"616"
Padding
=
"0,0,0,5"
<
Grid
HorizontalAlignment
=
"Center"
Background
=
"#FFEBEBEB"
Height
=
"543"
Width
=
"750"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"300*"
/>
</
Grid.ColumnDefinitions
>
<
Label
Content
=
"CustomerId:"
Height
=
"25"
HorizontalAlignment
=
"Left"
Name
=
"lblCustId"
Width
=
"40"
Margin
=
"9,45,0,0"
VerticalAlignment
=
"Top"
/>
<
TextBox
Height
=
"25"
HorizontalAlignment
=
"Left"
Margin
=
"50,45,0,0"
Name
=
"txtCustomerId"
VerticalAlignment
=
"Top"
Width
=
"75"
TabIndex
=
"0"
/>
<
Button
Content
=
"Submit"
Height
=
"25"
HorizontalAlignment
=
"Left"
Margin
=
"145,45,0,0"
Name
=
"btnSubmit"
VerticalAlignment
=
"Top"
Width
=
"75"
TabIndex
=
"1"
Click
=
"btnSubmit_Click"
/>
<
telerik:RadGridView
Name
=
"rgvCustomerImages"
Width
=
"750"
Margin
=
"0,190,0,0"
AutoGenerateColumns
=
"False"
IsReadOnly
=
"True"
>
<
telerik:RadGridView.ChildTableDefinitions
>
<
telerik:GridViewTableDefinition
>
<
telerik:GridViewTableDefinition.Relation
>
<
telerik:PropertyRelation
ParentPropertyName
=
"CustomerId"
/>
</
telerik:GridViewTableDefinition.Relation
>
</
telerik:GridViewTableDefinition
>
</
telerik:RadGridView.ChildTableDefinitions
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Customer Name"
DataMemberBinding
=
"{Binding CustomerName}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Age"
DataMemberBinding
=
"{Binding Age}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Gender"
DataMemberBinding
=
"{Binding Gender}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
<
telerik:RadGridView.HierarchyChildTemplate
>
<
DataTemplate
>
<
telerik:RadGridView
x:Name
=
"rgvCustomerOrderDetail"
ItemsSource
=
"CustomerOrderDetailList"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Order Id"
DataMemberBinding
=
"{Binding OrderId}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Order Date"
DataMemberBinding
=
"{Binding OrderDate}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Item"
DataMemberBinding
=
"{Binding ItemDescr}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Price"
DataMemberBinding
=
"{Binding Price}"
IsReadOnly
=
"True"
></
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
DataTemplate
>
</
telerik:RadGridView.HierarchyChildTemplate
>
</
telerik:RadGridView
>
</
Grid
>
</
Window
>
public
partial
class
CustomerSearch : Window
{
public
CustomerSearch()
{
InitializeComponent();
}
private
void
btnSubmit_Click(
object
sender, RoutedEventArgs e)
{
try
{
XmlDocument doc =
new
XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration(
"1.0"
,
null
,
null
);
doc.AppendChild(dec);
XmlNode root = doc.CreateElement(
"irRequest"
);
XmlElement eleSystem = doc.CreateElement(
"System"
);
XmlAttribute attSystem = doc.CreateAttribute(
"System"
);
attSystem.Value = ConfigurationManager.AppSettings[
"SystemName"
].ToString();
eleSystem.Attributes.Append(attSystem);
root.AppendChild(eleSystem);
XmlElement userName = doc.CreateElement(
"UserName"
);
userName.InnerText = App.UserName;
root.AppendChild(userName);
XmlElement customerId = doc.CreateElement(
"CustomerId"
);
customerId.InnerText = txtCustomerId.Text;
root.AppendChild(customerId);
doc.AppendChild(root);
XmlDocument customerSearchResponse =
new
XmlDocument();
string
strCustomers =
string
.Empty;
XmlDocument customerOrderSearchResponse =
new
XmlDocument();
string
strCustomerDetail =
string
.Empty;
using
(CustomerWebService.CustomerWebServiceClient customerSearchClient =
new
CustomerWebService.CustomerWebServiceClientt())
{
customerSearchClient.ClientCredentials.UserName.UserName = App.Url + App.UserName;
customerSearchClient.ClientCredentials.UserName.Password = App.Password;
customerSearchClient.Open();
strCustomers = customerSearchClient.GetCustomerById(doc.InnerXml);
customerSearchClient.Close();
}
using
(CustomerWebService.CustomerWebServiceClient client =
new
CustomerWebService.CustomerWebServiceClient())
{
client.ClientCredentials.UserName.UserName = App.Url + App.UserName;
client.ClientCredentials.UserName.Password = App.Password;
client.Open();
strCustomerDetail = client.GetCustomerDetailById(doc.InnerXml);
client.Close();
}
List<ImageAnalysisSession> ImageAnalysisSessionList =
new
List<ImageAnalysisSession>();
List<ImageData> ImageDataList =
new
List<ImageData>();
try
{
customerSearchResponse.LoadXml(strCustomers);
ImageDataList = GetImageData(customerSearchResponse);
customerOrderSearchResponse.LoadXml(strCustomerDetail);
ImageAnalysisSessionList = GetImageSessionData(customerOrderSearchResponse);
}
catch
(Exception ex)
{
string
err = ex.Message;
}
rgvCustomerImages.ChildTableDefinitions.Clear();
GridViewTableDefinition definition =
new
GridViewTableDefinition();
// definition.Relation = new PropertyRelation("Details");
rgvCustomerImages.ChildTableDefinitions.Add(definition);
rgvCustomerImages.ItemsSource = ImageDataList;
rgvCustomerImages.Rebind();
}
catch
(MemberAccessException mae)
{
string
err = mae.Message;
}
catch
(Exception ex)
{
string
err = ex.Message;
}
}
}
Thanks ~ Doug