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

[Solved] Error if binding GridViewComboBoxColumn to ViewModel

5 Answers 186 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Walter
Top achievements
Rank 1
Walter asked on 29 Jun 2010, 09:47 AM
Hello,

I am using a ViewModel and would like to bind a public CollectionViewSource to a GridViewComboBoxColumn.
The CollectionViewSource is definied as following:

 

 

ObservableCollection<ProgrammeVO> _programmeVOList = new ObservableCollection<ProgrammeVO>();

 

 

 

CollectionViewSource _programmeVOView = new CollectionViewSource();

 

 

 

public CollectionViewSource ProgrammeVOView

 

{

 

 

get { return _programmeVOView; }

 

 

 

set

 

{

_programmeVOView =

 

value;

 

OnPropertyChanged(

 

"ProgrammeVOView");

 

}

}

The grid column is definied as following:

<telerikGridView:GridViewComboBoxColumn
         UniqueName="ProgrammeID"
         ItemsSource="{Binding ProgrammeVOView.View}"
         Width="120">
    <telerikGridView:GridViewComboBoxColumn.Header>
        <TextBlock Text="SOS Children's Village Programme"
        TextWrapping="Wrap"
        VerticalAlignment="Center"
        HorizontalAlignment="Center"
        Margin="0,5"/>
    </telerikGridView:GridViewComboBoxColumn.Header>
</telerikGridView:GridViewComboBoxColumn>

If running the page I get an error message "AG_E_PARSER_BAD_PROPERTY_VALUE" within the

 

InitializeComponent().

Thank you for your assistance.
Daniel

 

 

 

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 29 Jun 2010, 01:08 PM
Hello Daniel Koffler,

The problem is in

ItemsSource="{Binding ProgrammeVOView.View}"

To have this working you will need to expose a instance of the ProgrammeVOView as a static resource and then use syntax like :

ItemsSource="{Binding Path=View, Source={StaticResource MyProgrammeVOView}}"

where MyProgrammeVOView} is the key of the resource .


Best wishes,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Walter
Top achievements
Rank 1
answered on 29 Jun 2010, 01:57 PM
Hello,

Thanks for your quick reply.
Could you please desribe briefly how to expose an instance of the ProgrammeVOView as a static resource?

Many thanks
Daniel Koffler
0
Walter
Top achievements
Rank 1
answered on 01 Jul 2010, 02:55 PM
Hello,

unfortunately I did not understand the way you suggested to solve the problem.
One thing which I maybe forgot to mention is that my viewmodel is already assigend to the data context of the user control.
I would like to access this viewmodel with the ItemsSource binding.

How can I achive this?

Thanks dor your assistance
Daniel Koffler
0
Accepted
Pavel Pavlov
Telerik team
answered on 02 Jul 2010, 03:02 PM
Hello Daniel Koffler,

I have prepared a small demo app to illustrate the approach . Please find it attached.

There is a view model ( MyViewModel)  which contains the ItemsSource for RadGridView ( Locations) and the ItemsSource for the ComboBoxColumn ( Countries) .

The ViewModel is instantiated as a static resource in XAML . It is also set as DataContext for the user control as per your requirements.

The ComboBoxColumn has its ItemsSource property bound to the static resource instance of MyViewModel.


Hope that helps .

Kind regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Walter
Top achievements
Rank 1
answered on 09 Oct 2010, 09:12 AM
Hello,

thank you for the example.

But in my scenario the viewmodel is instantiated  (not just assigned) in code behind because views/viewmodels are created and linked together dynamically. If adding the viewmodel to the XAML also it would be instantiated twice.

I found the following solution which might be interesting for others also
http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx

Daniel
Tags
GridView
Asked by
Walter
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Walter
Top achievements
Rank 1
Share this question
or