I'm having an issue binding a lookup field to a value in the grid.
Using RIA service RC I'm returning data like this. FirstName, LastName, RegionID....etc. I want to show the RegionName in the datacolumn rather than the ID value. So I created a converter and everything shows up fine but the filter now shows the Region Names but if you do an "Equals" filter in the UI it only works if you enter in an ID value (1,2,3,4,5). Although it shows the Region Names in the grid and the filter choices it will only filter on ID's. Am I missing something or is there a better way to do this? Just a heads up.....we cache all lookups on client side and would like to keep that.
<riaControls:DomainDataSource Name="CandidateDataSource" QueryName="GetCandidatesQuery" AutoLoad="True" FilterOperator="And">
<riaControls:DomainDataSource.DomainContext>
<web:NeuHireContext/>
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<TGridView:RadGridView x:Name="rgvCandidates" telerik:StyleManager.Theme="Office_Blue"
ItemsSource="{Binding ElementName=CandidateDataSource, Path=Data}"
SelectedItem="{Binding SelectedCandidate, Mode=TwoWay}" AutoGenerateColumns="False"
Background="{x:Null}" Grid.Row="1" Margin="10" RowStyle="{StaticResource GridViewRowStyle1}"
Foreground="{StaticResource DeepBlueTextBrush}" CanUserDeleteRows="False"
CanUserInsertRows="False" EditTriggers="None" DataLoadMode="Asynchronous"
RowIndicatorVisibility="Collapsed" >
<TGridView:RadGridView.Columns><TGridView:GridViewDataColumn Header="First Name" DataMemberBinding="{Binding FirstName}" /></TGridView:RadGridView.Columns>
<TGridView:GridViewDataColumn Header="Last Name" DataMemberBinding="{Binding LastName}" />
<TGridView:GridViewDataColumn Header="Region"
DataMemberBinding="{Binding PracticeID, Converter={StaticResource RegionIDToRegionConverter}}" />
</TGridView:RadGridView>
19 Answers, 1 is accepted
Forget it......instead of using the converters and caching the lookups I decided to return [include] the data from the service.
(b) Section of my metadata class
It does not become quite clear what exactly is the problem . Maybe if I see the attachment it would help.
You are speaking of images of your objects. Please let me see them .
All the best,
Pavel Pavlov
the Telerik team
It occured to me the attachments were not included. I just tried using the Code Block instead of attaching the files but got a message saying the server had some issues. Will try again.
Loaded images in a SkyDrive folder. Pls use hyperlink below. Thanks again!
J
Attachments Here
After reviewing your screenshots it occured to me that we have a very simillar online example.
Plese follow the approach demonstrated in this blogpost.
Sincerely yours,
Pavel Pavlov
the Telerik team
Hi Pavel,
I have seen that blogpost before.
The difference between that and mine is that mine uses multiple entities for the datagrid Master.
In the blogpost the Master uses one entity and the Detail uses another.
All I need is to be able to see data for the lookup tables on the Master section of the gridview. I am using the Detail section to show the employees who report to the selected Master (self-referencing hierarchy)
Thanks again!
J
It seems a little bit confusing . Can you please provide a screenshot of what you expect the RadGridView to look like - maybe you can prepare some mockup in Excel which will help avoid confusion. I am beginning to think you need something like a GridViewComboBox column in the Master grid to display the lookup data - is that correct ?
Best wishes,
Pavel Pavlov
the Telerik team
Ok ,
Here is the simplest way to show the LastName :
Make the column which should show the Last Name a GridViewComboBoxColumn . ( I know you may not need the combobox , we will just use the lookup capabilities of the column) .
Set up the properties of the column the following way :
ItemsSource = the collection of contacts entities
DisplayMemberPath = "LastName"
SelectedValuePath = "ContactID" / or whatever is the name of the ID property in the Contact entity/
DataMemberBinding = "ContactID" / or whatever is the name of the ID property in the Employee entitiy/
This should be enough to harnes the column to translate ContactID's to LastNames and show them in the cell.
* additionally you may disable the editing of the column ( IsReadonly="true" ) in order to prevent the appearance of a combobox if the user enters edit mode.
Hope that helps.
Kind regards,
Pavel Pavlov
the Telerik team
ComboBox column will sort by the value member, not by the display member as you have observed.
So this is the downside of such approach.
Having an Entity view with the joined names is a good solution , but it has more to do with RIA rather than with RadGridView. Actually - performing the "lookup" logic at the server is the best choice. Once you have the view , there is no problem to display it in RadGridView.
Best wishes,
Pavel Pavlov
the Telerik team
I had already created a multi-table view in SQL Server with the lookup values already returned. After updating my model from the database, that view became the entity I am now using to load the employee data.
So far so good....
J
Now I have the fields display properly and I can sort by lookup data on the gridview. I have a main datagrid which has a few key columns -including lookup data- to identify the employees and do basic sorting and grouping; and a details grid (not quite a dataform) which has the employee details and user controls to perform the other CRUD operations.
As mentioned earlier, to achieve this I had to let my entity be based on a multi-table SQL Server View. There are now two problems:
1. I can't edit any field on my details grid - even those from non-lookup tables. For example when i tried editing a field from the main Employee table, i get a read-only error because all the fields have the following attribute in the .gc.cs file: [Editable(false, AllowInitialValue=true)]
2. The SQL SERVER View has contact and address details that are stored in linked tables - Contact and Address.
In the details grid, i have a button that allows me to add new contact which has fields in a Contact and an Address table. This contact could easily be the spouse of the employee or any other next of kin. I can place the fields for this new contact directly on the details grid or on a popup child window.
Question : "How do I save the new information back to the Contact and Address tables - assuming question 1 has been addressed?"
Is there any advantage in converting my SQL SERVER VIEW to a Stored Proc?
Am I going about this the wrong way?
Kindly help.
J
Since these are more RIA-specific questions rather than RadGridVIew -related, I am not sure I can be of great help here.
However I believe when you create your model , there is an option ( checkbox ) to specify entities to be editable.
Regards,
Pavel Pavlov
the Telerik team
I'm no ria services specialist but I'll share with you how I did as I had the same problems...
You could try to add an [Editable(true, AllowInitialValue=true)] in your metadata. This will make the normal fields editable but then I got stuck later with other problems.
In fact what I did is use composition instead of using views. You should try not to do the work in the database in place of the entity framework. So for exemple with your view, replace it with a composition. Meaning: extract the field you require using linq and build a custom object holding the fields from the diffrent tables you need... Here you can find many good samples on what you can do with ria wcf services, including composition :)
http://martinkruszynski.blogspot.com/2010/08/wcf-ria-services-v10-samples-part-ii.html
Now if what you need is making your views persist things, you should take a look here, Deny Table Access to the Entity Framework Without Causing a Mutiny:
http://msdn.microsoft.com/en-us/magazine/ff898427.aspx
So yes, I would say you are going the wrong way. Take a look at composition.
Here you don't need a view. I don't know your exact model. Just put each info in it's own table then link them using relations. Add an People.Include("contact").include("address") in your linq query, then add the [include] attribute to the people contact and address field metadata...
After that if you want to add a contact to people, you just do a New Contact(); then people.Contacts.Add(contact); You don't need to fill the contact ID as this is done automatically for you... etc...
I can't help you much more, you will find everything you need in the samples I point you to ;)
Good luck with that...
John.
ps: pavel, I like the GridViewComboBoxColumn tips a lot, thanks ;)
<
telerik:GridViewComboBoxColumn
ItemsSource
=
"{Binding Path=Data, Source={StaticResource translationDomainDataSource}}"
DisplayMemberPath
=
"en"
SelectedValueMemberPath
=
"TranslateID"
DataMemberBinding
=
"{Binding Program.Title}"
Header
=
"Nom du Programme"
Width
=
"2*"
IsReadOnly
=
"True"
/>
I'm binding this to a static domain data source (here in page)...
<
navigation:Page.Resources
>
<
riaControls:DomainDataSource
AutoLoad
=
"True"
x:Key
=
"translationDomainDataSource"
QueryName
=
"GetDataTranslatesQuery"
LoadedData
=
"DomainDataSource_LoadedData"
>
<
riaControls:DomainDataSource.DomainContext
>
<
my:AkDomainContext
/>
</
riaControls:DomainDataSource.DomainContext
>
</
riaControls:DomainDataSource
>
</
navigation:Page.Resources
>
I hope it helps,
John.
Thanks for your tips. I agree with you about SelectedValueMemberPath. That was what i eventually had to use. I also agree with you on the linq queries. I moved on to them as well. One thing i am trying to use less of these days is DomainDataSource. I have embraced the MVVM concept and started "re-engineering" my solution to take full benefit of the testability angle. It has meant redoing a few classes and controls, but i reckon i will be a lot better off in terms of maintenance in the long run. We could share some thoughts on these later.
Kind Regards!
J
John.