Binding to a different collection

4 posts, 0 answers
  1. Wellpartner
    Wellpartner avatar
    18 posts
    Member since:
    Aug 2010

    Posted 27 Dec 2017 Link to this post

    I'm converting from 2011.3.1116.35 to 2017-3-913.40.  This works in the old version but not in the new version.

    My RadGridView is bound to an ObservableCollection named DrugList, however the ComboBoxColumn is bound to a different ObservableCollection named BrandGenericCodeList.  I'm trying to do the binding in XAML:

    <UserControl x:Class="MyApp.ucDrug"
                    <telerikGrid:RadGridView x:Name="radGridView"
                                             ItemsSource="{Binding DrugList}"
                            <telerikGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding DrugName}" />
                            <telerikGrid:GridViewComboBoxColumn Header="Brand/Generic"
                                                                DataMemberBinding="{Binding BrandGenericCode}"
                                                                ItemsSource="{Binding BrandGenericCodeList}"
                                                                UniqueName="BGC" />


    Any help is appreciated.  Thank you.

  2. Wellpartner
    Wellpartner avatar
    18 posts
    Member since:
    Aug 2010

    Posted 28 Dec 2017 in reply to Wellpartner Link to this post

    I was able to do this in code:
    ((GridViewComboBoxColumn)this.radGridView.Columns["BGC"]).ItemsSource = BrandGenericCodeList;

    ... but am wondering if it's possible to do this in XAML?

  3. Dilyan Traykov
    Dilyan Traykov avatar
    898 posts

    Posted 29 Dec 2017 Link to this post

    Hello Wellpartner,

    Could you please clarify whether the DrugList and BrandGenericCode properties belong to the same class and are both public properties? If that is not the case, you may need to explicitly set a Source or RelativeSource for the binding. Here's an example:

    ItemsSource="{Binding DataContext.BrandGenericCodeList, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"

    For your convenience, I've also prepared a small sample project which demonstrates a similar setup where the column is bound as expected.

    Please let me know if you find this helpful.

    Dilyan Traykov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  4. Wellpartner
    Wellpartner avatar
    18 posts
    Member since:
    Aug 2010

    Posted 29 Dec 2017 in reply to Dilyan Traykov Link to this post

    Hi Dilyan, this works great - thanks very much!
Back to Top