Binding Lookup Values

20 posts, 0 answers
  1. Greek1
    Greek1 avatar
    4 posts
    Member since:
    Jan 2010

    Posted 15 Jun 2010 Link to this post

    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:GridViewDataColumn Header="Last Name" DataMemberBinding="{Binding LastName}" />
    <TGridView:GridViewDataColumn Header="Region" 
                    DataMemberBinding="{Binding PracticeID, Converter={StaticResource RegionIDToRegionConverter}}"
     />
     
    </TGridView:RadGridView.Columns>
    </TGridView:RadGridView>
  2. Greek1
    Greek1 avatar
    4 posts
    Member since:
    Jan 2010

    Posted 15 Jun 2010 Link to this post



    Forget it......instead of using the converters and caching the lookups I decided to return [include] the data from the service. 
  3. DevCraft banner
  4. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 22 Jun 2010 Link to this post

    Hello,
    I have tried using [Include] without any luck.
    I am trying to show the EmployeeID, LastName, FirstName (amongst other data in other lookup tables) in a gridview.
    I have attached images of the objects
    (a) is a section of my model - which shows a 1 to 1 relationship between Employee and Contact.
    (b) Section of my metadata class
    (c) My GetEmployee procedure
    (d) My DDS declaration
    (e) and finally, my gridview declaration

    Grateful if someone could point out to me what I am missing. This is my 3rd day fighting over this.
    Thanks
    J
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 23 Jun 2010 Link to this post

    Hello jay,

    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
    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
  6. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 23 Jun 2010 Link to this post

    Thanks, for your interest in this, P!
    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
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 28 Jun 2010 Link to this post

    Hello jay,

    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
    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
  8. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 28 Jun 2010 Link to this post

    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

  9. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 28 Jun 2010 Link to this post

    Hi jay,

    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
    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
  10. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 28 Jun 2010 Link to this post

    Hi Pavel,

    The attached image shows what I am trying to achieve. 
    In this scenario, Employees 2,4,5,6 & 7 report to Employee 1, and can be seen when I expand the + box at the left. This bit is working great as i can clearly see which employee has direct reports and who they are. My ONLY current need is to populate the LastName column in the header section of the grid.

    How can I modify my code to make LastName, which comes from a Contact lookup entity, show up? As I said earlier, there is a 1 to many relationship between the Employee and Contact entities. For a give record in Employee, there can be several records in Contact, the first of which will have a contactType of 'Self'. Other records can be Spouse, NextofKin...........

    Thanks!
    J


  11. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 01 Jul 2010 Link to this post

    Hello jay,

    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
    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
  12. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 01 Jul 2010 Link to this post

    Thanks Pavel. This finally did it even though I sometimes have to click on the gridcell for the value to show.

    Thanks again!
    J
  13. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 03 Jul 2010 Link to this post

    Hi Again, Pavel.
    Lookup data now displays correctly on the gridview header.
    With your suggested implementation, would it be possible to sort by LastName by clicking the GridViewComboBoxColumn header? 
    I tried it but the rows are not ordered alphabetically.  It is very important for me to be able to sort by LastName on the gridview. If not possible, given what I want to achieve, can I simply have an "Entity view" that already joins the Employee and other lookup tables so i can get sortable LastNames on the Grid header. Any downside to this approach?

    Thanks for your patience.

    J
  14. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 05 Jul 2010 Link to this post

    Hello jay,

    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
    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
  15. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 05 Jul 2010 Link to this post

    Thanks again, Pavel.
     
    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
  16. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 11 Jul 2010 Link to this post

    Hmm. I thought I was home free....
    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)]
    Question : "Is it possible to make this entity writeable and edit its fields ?" . BTW, the view is editable in SQL SERVER.

    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
  17. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 15 Jul 2010 Link to this post

    Hello jay,

    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
    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
  18. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 04 Sep 2010 Link to this post

    Hello Jay,
    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 ;)
  19. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 05 Sep 2010 Link to this post

    Also, just to add a sample because I did not find Pavel's SelectedValuePath, I may be wrong but SelectedValueMemberPath, worked for me.

        <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.
  20. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 06 Sep 2010 Link to this post

    Hi 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
  21. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 06 Sep 2010 Link to this post

    Sure... see you around ;)
    John.
Back to Top
DevCraft banner