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

Wpf equivalent of ValueMember/DisplayMember

7 Answers 465 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jholt
Top achievements
Rank 1
jholt asked on 29 Oct 2008, 11:05 PM
Is there a way to bind to lookup values in a gridview?

What I'm trying to achieve is nothing more complex than in Windows Forms ValueMember and DisplayMember:
This code is from the RadControls for WinForms example:Column Types
          
  //add new lookup column             
  GridViewLookUpColumn lookUpColumn = new GridViewLookUpColumn();             
  lookUpColumn.HeaderText = "Look up";                      
  lookUpColumn.FieldName = "PersonID";             
  lookUpColumn.DataSource = this.employeesBindingSource;             
  lookUpColumn.ValueMember = "EmployeeID";             
  lookUpColumn.DisplayMember = "LastName"

Given the classes below where the GridView binds to PriceList which is a collection of Price(s), I want the CommodityId column to be a combo box which, when in edit mode gives me a list of Commodity entities showing the Description text and when in view  mode shows me the Description text, but saves the Commodity.Id value back to AppPresenter.PriceList.

By including DataMemberPath in the CommodityId field of the DataView, I am able to display Commodity.Description. However, the selected value from the combo is not reflected in the underlying datasource (PriceList).
If I remove DataMemberPath from the markup - it is clear to see that the PriceList is never updated with the newly selected value.

I'm guessing that the reason for this is that I am not binding Commodity.Id (in the lookup) to CommodityId in the GridView. So my question is - how do I do this binding? The example for DataBinding doesn't seem to cover this case.


public class Commodity() 
    public int Id {get;set;} 
    public string Description {get;set;} 
     
    public override ToString() 
    { 
        return Description; 
    } 
 
public class Price 
    public int Id {get;set;} 
    public DateTime Date {get;set;} 
    public int CommodityId {get;set;} 
    public EntityRef<Commodity> Commodities {getset;} 
public class AppPresenter 
    public ObservableList<Price> PriceList {get;} 
 
public class Shell 
    pubic Shell() 
    private IList<Commodity> _commodityList; 
    { 
        InitializeComponents();  
         
        _commodityList = repository.GetCommodites(); 
        colCommodityEditorSettings = new ComboBoxEditorSettings { ItemsSource = _commodityList};             
            colCommodity.EditorSettings = colCommodityEditorSettings; 
        } 

 
 <telerik:RadGridView Grid.ColumnSpan="4" Grid.Row="3" Margin="5" x:Name="radGridView1" ColumnsWidthMode="Auto" ItemsSource="{Binding Path = PriceList}"  
                             AutoGenerateColumns="False"
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="ID" UniqueName="Id" x:Name="colId" /> 
                <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="Date" UniqueName="Date" IsAutoGenerated="False" IsVisible="True" x:Name="colDate" /> 
                <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="Hidden" UniqueName="IsHidden" x:Name="colIsHidden" /> 
                <telerik:GridViewDataColumn DataType="{x:Null}" HeaderText="Commodity" UniqueName="CommodityId" x:Name="colCommodity" DataMemberPath="Commodities.Description">   
</telerik:RadGridView>                 
 
 

Many thanks in advance for your help
Jeremy Holt

7 Answers, 1 is accepted

Sort by
0
Bronwen
Top achievements
Rank 2
answered on 30 Oct 2008, 10:48 PM
Hi jholt,

Check out the last reply on the question I raised here: http://www.telerik.com/community/forums/thread/b311D-bgkmkk.aspx

It provides an example of this.
0
jholt
Top achievements
Rank 1
answered on 30 Oct 2008, 11:06 PM
Hi,

Support directed me to the link and I downloaded the file. It just strikes me that it is an incredibly complicated way to do something that should really be a basic requirement in any kind of datagrid - namely do a lookup by foreign key. In fact if one is going to use any embedded control in a cell the requirement is always going to be the same - bind the result from the embedded control to the underlying data of the field in the grid.

I'm very very new to Wpf - so maybe it's just me - I still have to think very hard about Bindings and Templates....

Regards
Jeremy


0
Bronwen
Top achievements
Rank 2
answered on 31 Oct 2008, 01:15 AM
I agree...lots of code for something that I'm going to do ALL the time. Would have expected a way to just add the binding properties I needed.

Hoping that next version/s will improve this.
0
jholt
Top achievements
Rank 1
answered on 31 Oct 2008, 10:43 AM
+1 from me
0
Dimitar Dobrev
Telerik team
answered on 31 Oct 2008, 05:52 PM
Hello, Jeremy, Branwen,

Unfortunately, we are not able to provide a simpler solution for this problem right now. We have in our feature list the ability to create your editors from XAML. Your feedback gives higher priority to this feature and will surely help it be included in one of our future releases.
 
Regards,
Dimitar Dobrev,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dylan
Top achievements
Rank 1
answered on 15 Apr 2015, 02:20 PM
This is a very old thread, but I would like to say that I am shocked that - 7 YEARS later - this is still not a feature.  Is there much effort being put into wpf control development?
0
Dimitrina
Telerik team
answered on 16 Apr 2015, 07:46 AM
Hello,

I can suggest you consider our GridViewComboBoxColumn and configure it as explained in ComboBox Column article. You can also check various other examples available with the SDK Samples Browser and also the "ComboBox ColumnWPF Demo.

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
GridView
Asked by
jholt
Top achievements
Rank 1
Answers by
Bronwen
Top achievements
Rank 2
jholt
Top achievements
Rank 1
Dimitar Dobrev
Telerik team
Dylan
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or