How to display the foreign key value in grid

7 posts, 0 answers
  1. Bronwen
    Bronwen avatar
    54 posts
    Member since:
    Sep 2008

    Posted 05 Oct 2008 Link to this post

    I want to display the textual value of a foreign key, while binding to the id value in the orginal table in the grid and in edit have a combo box to edit.

    e.g  in a normal combo i would do something like:
    <ComboBox Name="TypecomboBox" ItemsSource="{Binding Source={StaticResource personTypesData }}" DisplayMemberPath="Name" SelectedValuePath="PersonTypeID" SelectedValue="{Binding Path=PersonTypeID}" />

    What's the equivalent to this in the grid control?

    I can set the grid to edit as a combo using the comboeditor.  How do i display the textual value rather than the ID?
  2. Dimitar Dobrev
    Admin
    Dimitar Dobrev avatar
    44 posts

    Posted 06 Oct 2008 Link to this post

    Hello Bronwen,

    You may check the "Editors" example in our sample application to see if the approach used there meets your requirements. We are currently working on an advanced example but to finish it properly we would need some additional information about your object model (that is, if you use data sets and data tables, or business objects). Can you provide more info on how you bind the grid or maybe even post a code snippet.

    Unfortunately, at the moment displaying the foreign key in the grid is not easy to achieve in some situations. The easier part is getting the editors to display the text, we will be able to achieve this.

    Thank you for your patience. We are looking forward to continuing our discussion.

    Sincerely yours,
    Dimitar Dobrev,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Bronwen
    Bronwen avatar
    54 posts
    Member since:
    Sep 2008

    Posted 06 Oct 2008 Link to this post

    Hi, I've looked at the editor example. I can get the combo to display and edit the correct field in edit...just not display the displayname in view mode..i don't want the user seeing the id field.

    I'm using Linq To SQL. So my Person Object has the following fields:

    PersonID
    Name
    ...
    PersonTypeID
    PersonType -> Which then has PersonTypeID and Name.

    Instead of displaying:
    Bob, 1
    I want to display:
    Bob, General Staff

    and in edit i want the PersonTypeID field updated..not the name field in the person type table.
  5. Dimitar Dobrev
    Admin
    Dimitar Dobrev avatar
    44 posts

    Posted 09 Oct 2008 Link to this post

    Hello Bronwen,

    We managed to create an example for your case, in three steps.
    1. The first step was a class representing custom editor settings for the comboboxes. This class transfers the properties you set to it to each combo editor.
    2. The second class is a custom combo box editor, which makes use of the properties supplies by the editor settings. This class also contains some code to make sure the initial value of type PersonType is selected in the combo box.
    3. The last step is a small change in the control template of the cells in the PersonType column, which assures that only the name of the person type is displayed:
    Content="{Binding Data.PersonType.Name}" 
     

    If you have any other questions for us, we will be happy to assist you.

    Regards,
    Dimitar Dobrev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Scott Christian
    Scott  Christian avatar
    6 posts
    Member since:
    May 2009

    Posted 17 Jul 2009 Link to this post

    Is this approach still valid with the Q2 release? If not please post how to accomplish this with the Q2.
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 22 Jul 2009 Link to this post

    Hi Scott Christian,

    You can configure the combo box column to achieve this scenario. Here is a little code snippet:

                GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn(); 
                comboColumn.Header = "Type"
                comboColumn.DataMemberBinding = new Binding("PersonTypeID") {Mode = BindingMode.TwoWay}; 
                comboColumn.ItemsSource = PersonType.PersonTypes; 
                comboColumn.DisplayMemberPath = "Name"
                comboColumn.SelectedValueMemberPath = "ID"
                this.grid.Columns.Add(comboColumn); 
     

    I have attached the whole project that the above code snippet is from. Please examine it and let me know if you have any questions.

    All the best,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Carina
    Carina avatar
    41 posts
    Member since:
    Nov 2012

    Posted 12 Dec 2012 Link to this post

    Hello,
     
    Do you happen to have this in VB.net?
Back to Top
UI for WPF is Visual Studio 2017 Ready