Wpf equivalent of ValueMember/DisplayMember

8 posts, 0 answers
  1. jholt
    jholt avatar
    21 posts
    Member since:
    May 2007

    Posted 29 Oct 2008 Link to this post

    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; 
            _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}"  
                    <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">   

    Many thanks in advance for your help
    Jeremy Holt

  2. Bronwen
    Bronwen avatar
    54 posts
    Member since:
    Sep 2008

    Posted 30 Oct 2008 Link to this post

    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.
  3. jholt
    jholt avatar
    21 posts
    Member since:
    May 2007

    Posted 30 Oct 2008 Link to this post


    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....


  4. Bronwen
    Bronwen avatar
    54 posts
    Member since:
    Sep 2008

    Posted 30 Oct 2008 Link to this post

    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.
  5. jholt
    jholt avatar
    21 posts
    Member since:
    May 2007

    Posted 31 Oct 2008 Link to this post

    +1 from me
  6. Dimitar Dobrev
    Dimitar Dobrev avatar
    44 posts

    Posted 31 Oct 2008 Link to this post

    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.
    Dimitar Dobrev,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Dylan
    Dylan avatar
    1 posts
    Member since:
    Nov 2014

    Posted 15 Apr 2015 Link to this post

    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?
  8. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 16 Apr 2015 Link to this post


    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.


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

Back to Top