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

Binding to a different collection

3 Answers 103 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Wellpartner
Top achievements
Rank 1
Wellpartner asked on 27 Dec 2017, 08:10 PM

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"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" 
             xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
...
                <telerikGrid:RadGridView x:Name="radGridView"
                                         Grid.Row="1"
                                         AutoGenerateColumns="False"
                                         CanUserDeleteRows="True"
                                         IsSynchronizedWithCurrentItem="True"
                                         ItemsSource="{Binding DrugList}"
                                         ShowColumnFooters="True"
                                         Deleting="radGridView_Deleting"
                                         RowValidating="radGridView_RowValidating"
                                         SelectionChanged="radGridView_SelectionChanged">
                    <telerikGrid:RadGridView.Columns>
                        <telerikGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding DrugName}" />
                        <telerikGrid:GridViewComboBoxColumn Header="Brand/Generic"
                                                            DataMemberBinding="{Binding BrandGenericCode}"
                                                            DisplayMemberPath="Value"
                                                            IsLightweightModeEnabled="True"
                                                            ItemsSource="{Binding BrandGenericCodeList}"
                                                            SelectedValueMemberPath="Name"
                                                            UniqueName="BGC" />

 

Any help is appreciated.  Thank you.

3 Answers, 1 is accepted

Sort by
0
Wellpartner
Top achievements
Rank 1
answered on 28 Dec 2017, 05:11 PM

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?

0
Dilyan Traykov
Telerik team
answered on 29 Dec 2017, 04:57 PM
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.

Regards,
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.
0
Wellpartner
Top achievements
Rank 1
answered on 29 Dec 2017, 06:08 PM
Hi Dilyan, this works great - thanks very much!
Tags
ComboBox
Asked by
Wellpartner
Top achievements
Rank 1
Answers by
Wellpartner
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or