I created a set of LINQ classes, Customers.Memberships.CertificatesUsed
First, I want to display the records from the Certificates collection
I tried the sample code below but it doesn't seem to work
<telerik:RadGridView AutoGenerateColumns=
"False"
ItemsSource=
"{Binding Path=Memberships.CertificatesUsed}"
>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header=
"Membership ID"
UniqueName =
"MembershipID"
DataMemberBinding="{Binding Path=MembershipID}">
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header=
"Certificate No"
UniqueName =
"CertificateNo"
DataMemberBinding="{Binding Path=CertificateNo}">
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header=
"Date Used"
UniqueName =
"DateUsed"
DataMemberBinding="{Binding Path=DateUsed}">
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
How should I bind the grid to the Certificates list?
Next, I want to be able to filter the content of the grid based on the selected Membership ID from a separate combo box.
How do I do it?
Thanks!
5 Answers, 1 is accepted
Basically, it depends on what the DataContext of the grid is, whether the collection is available at the grid level, etc. So, in order to provide you any further assistance on that, I would need a bit more information about your settings. Still I am sending you a sample project illustrating a possible approach for using LINQ with RadGridView.
Considering your second scenario, you may get the SelectedValue of the RadComboBox and set the ItemsSource of the grid to the filtered source (possibly using Where() clause).
Maya
the Telerik team
<
ComboBox
ItemsSource
=
"{Binding Memberships}"
SelectedValuePath
=
"MembershipID"
DisplayMemberPath
=
"MembershipID"
IsSynchronizedWithCurrentItem
=
"True"
>
</
ComboBox
>
<
telerik:RadGridView
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding Memberships/CertificatesUsed}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Membership ID"
UniqueName
=
"MembershipID"
DataMemberBinding
=
"{Binding Path=MembershipID}"
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Certificate No"
UniqueName
=
"CertificateNo"
DataMemberBinding
=
"{Binding Path=CertificateNo}"
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"Date Used"
UniqueName
=
"DateUsed"
DataMemberBinding
=
"{Binding Path=DateUsed}"
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
My problem here now is everytime the value of the selected item in the combobox changes, it takes a while for the RadGridView to change it's content. It seems the delay is in the rendering of the new content, not in changing the data.
Data comes from an ASP.Net webservice returning a customer record with a list of memberships and each membership can have a list of used certificates. The webservice gets the list through LINQ. The combo box is filled as soon as data is returned. The RadGridView is only filled up when the selected item changes in the combobox.
The form's data context is set to Customer.
Anything I should look at to improve the performance?
Thanks!
Another possible approach - and most probably faster in this case - would be to use the filtering functionality of the grid, thus relaying on its own data engine. What you can do is to add initially a FilterDescriptor (its initial value will be unset) and once you get the SelectedItem from the ComboBox, to define the Value property of the FilterDescriptor to be equal to this SelectedItem.
You may take a look at our online documentation for further reference on Filtering the RadGridView.
Maya
the Telerik team
Thanks for the advise. I did that and got it to work but the performance problem still remains. Performance is still the same as the previous example.
What I did to isolate the issue was to change to autogenerated columns, instead of manual column binding. This improved the performance significantly. This confirms my suspicion that the problem is in the rendering. What's odd about this is, so far, this is the only grid that's having performance problems. I recreated the scenario in a separate WPF project and my assessment was confirmed. Although there is a big difference in performance between the two applications, the sample project being much faster in rendering, there is still delay in rendering the data when manually binding columns to fields.
Anyway, I'm leaving it to autogenerated columns for now and just adjust the look of the grid at runtime.
I hope you can get back to me on possible workarounds using automatic binding.
Thanks!
It would be really great if you could send us a sample project where you reproduce the issue, so that we could investigate it locally and consider your exact settings and requirements. Thus we will be able to provide you with the most appropriate for your case solution.
Maya
the Telerik team