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

GridViewComboBoxColumn: howto check ItemsSource Property

3 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
hermann
Top achievements
Rank 1
hermann asked on 12 Jul 2011, 10:26 PM
Hi there,
I have a GridViewComboBoxColumn in a nested hierarchical GridView, but somehow I can't set ItemsSource, DataMemberBinding and SelectedValueMemberPath properly from XAML. So, is there a simple way to find out, which ItemsSource is really set in the nested Grid at runtime, in order to fix the other props?
btw, my error looks like
BindingExpression path error: 'Name' property not found on 'object' ''Char' (HashCode=5177423)'. BindingExpression:Path=Name; DataItem='Char'
Cheers,
Hermann

3 Answers, 1 is accepted

Sort by
0
hermann
Top achievements
Rank 1
answered on 13 Jul 2011, 12:13 PM
Hi again,
this is really odd!
when I set the ItemsSource of my ComboBoxColumn in C# (at runtime) it works like a charm,
whenn I try to set it in XAML (at design time) it looks like its never been set, and all bindings go wrong due to an empty ItemsSource.
Can someone confirm this? Is this a bug??
0
hermann
Top achievements
Rank 1
answered on 13 Jul 2011, 06:25 PM
Next perception:
Binding to ComboBoxColumn ItemsSource means: your item source must be a collection property 2 levels up to your current nested gridview level.
So, for a simple GridView, you bind the DataContext of the whole grid (level0) with resource key  (e.g. MyViewModel)
then in the GridView (level1), you bind to the collection in the DataContext(e.g. DataRows)
then in the GridViewComboBoxColumn  using ItemsSource you bind to a collection two levels up (in level0 - the DataContext).

In case of a nested gridview with a comboboxcolumn be aware, that your ItemsSource bound collection should be 2 levels up in the hierarchy. It is not the DataContext object, that provides the collection, but some nested grid 2 levels up!

Binding a ComboBoxColumns ItemsSourceBinding means: the collection providing object is always just one level up!

This is new to me, since I always thought, that ItemsSource binding means the top level DataContext, which makes more sense to me - if you have hierarchical gridview layout...
0
Dimitrina
Telerik team
answered on 15 Jul 2011, 07:09 AM
Hello Hermann,

You should expose the ViewModel as a static resource on the page and then use it by the binding. This is explained in this help article.

May you please try this and share with us if it solves your problem?

Kind regards,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
hermann
Top achievements
Rank 1
Answers by
hermann
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or