This is a migrated thread and some comments may be shown as answers.

How to display the foreign key value in grid

6 Answers 648 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bronwen
Top achievements
Rank 2
Bronwen asked on 05 Oct 2008, 11:30 PM
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?

6 Answers, 1 is accepted

Sort by
0
Dimitar Dobrev
Telerik team
answered on 06 Oct 2008, 07:22 PM
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.
0
Bronwen
Top achievements
Rank 2
answered on 06 Oct 2008, 10:47 PM
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.
0
Dimitar Dobrev
Telerik team
answered on 09 Oct 2008, 10:17 AM
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.
0
Scott Christian
Top achievements
Rank 1
answered on 17 Jul 2009, 07:04 PM
Is this approach still valid with the Q2 release? If not please post how to accomplish this with the Q2.
0
Rossen Hristov
Telerik team
answered on 22 Jul 2009, 03:18 PM
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.
0
Carina
Top achievements
Rank 1
answered on 12 Dec 2012, 06:00 PM
Hello,
 
Do you happen to have this in VB.net?
Tags
GridView
Asked by
Bronwen
Top achievements
Rank 2
Answers by
Dimitar Dobrev
Telerik team
Bronwen
Top achievements
Rank 2
Scott Christian
Top achievements
Rank 1
Rossen Hristov
Telerik team
Carina
Top achievements
Rank 1
Share this question
or