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

Binding from RadGridView to RadComboBox

10 Answers 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 07 Mar 2011, 08:38 PM
I have a combobox in a gridview in my silverlight application.

    <Controls1:GridViewComboBoxColumn Header="Accomplishment Category"
    ItemsSource="{Binding AccomplishmentCategoryList}"
    DataMemberBinding="{Binding AccomplishmentCategoryValue}"  
    SelectedValueMemberPath="{Binding AccomplishmentCategoryValue}">
    </Controls1:GridViewComboBoxColumn>

I am able to get my grid to display the results for its own itemSource.

    <Controls1:RadGridView x:Name="Accomplishments" Grid.Row="1" CanUserInsertRows="True"
    ShowInsertRow="True" CanUserDeleteRows="True" RowIndicatorVisibility="Visible"
    IsReadOnly="False" ItemsSource="{Binding AccomplishmentResults, Mode=TwoWay}">

The AccomplishmentResults collection binds perfectly. my issue is the combobox does not display anything until you actually click on the column that contains the combobox control. so that column looks empty, when you click on the column the results are displayed, when you click again you get the combobox that will show the items in that collection..if you select anything other than that column those values disappear and are empty again. if you select the row they remain empty..it is only when the column is selected that the values appear.

10 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 08 Mar 2011, 08:18 AM
Hi George,

You may take a look at this troubleshooting article for a reference.
 

Kind regards,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
George
Top achievements
Rank 1
answered on 08 Mar 2011, 11:06 AM
The element name doesnt seem to be my issue. my xaml is below

<Controls1:GridViewComboBoxColumn Header="Accomplishment Category"  ItemsSource="{Binding AccomplishmentCategoryList}" DataMemberBinding="{Binding AccomplishmentCategoryValue}"  SelectedValueMemberPath="{Binding AccomplishmentCategoryValue}"></Controls1:GridViewComboBoxColumn>

and the second solution wont work as we are using an MVVM pattern and we dont want to set anything in the code behind.
0
Maya
Telerik team
answered on 08 Mar 2011, 11:13 AM
Hello George,

May you try to define your ViewModel in the Resource section of the UserControl and use it as a StaticResource afterwards ?

<UserControl.Resources>
   <local:MainPageViewModel x:Key="mainPageViewModel" />
</UserControl.Resources>
...
<telerik:GridViewComboBoxColumn Header="Category"
           DataMemberBinding="{Binding CategoryID}"
           ItemsSource="{Binding Path=Categories, Source={StaticResource mainPageViewModel}}"
           DisplayMemberPath="CategoryName"
           SelectedValueMemberPath="CategoryID" />


 

All the best,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
George
Top achievements
Rank 1
answered on 08 Mar 2011, 08:38 PM
Just to follow up with you. We are using an MVVM Framework that will make what you are suggesting difficult. We are already binding the view and view model another way and doing it as you describe would be quite difficult. if you have any other solutions please let me know.

thanks - George
0
Maya
Telerik team
answered on 09 Mar 2011, 02:00 PM
Hello George,

Basically, the behavior you experience is due to the difference between the DataContext of the row (which is the item itself) and the one of the column. Consequently, unless being set explicitly, the data for the column will be available on getting focus. That is why the two possible approaches are either to set the ItemsSource in the code-behind or through the Source property of the binding with a StaticResource.
Yet another possibility may be to use the ItemsSourceBinding of the GridViewComboBoxColumn. However, in this case you will have to expose a new property in our business object that holds the items for the column.
 

Kind regards,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Ubuntu
Top achievements
Rank 1
answered on 26 Apr 2011, 02:54 PM
Hello Maya,

Allow me ask .... Does setting ItemsSourceBinding solve the issue.
I mean I export a property form my VM that holds the items, but is doesn't show up unless I add that property to the page resource.

Is this what you meant by using ItemsSourceBinding the or I understood that ...

Regards
0
Maya
Telerik team
answered on 26 Apr 2011, 03:32 PM
Hello George,

If you want to use the ItemsSourceBinding, you have to expose a property in your business object that will contain the source for the GridViewComboBoxColumn. So, let us say that you have an object of type Person that will be the data item for the grid. You may add a property
- ObservableCollection<Country> Countries {get;set;} 
Afterwards, you may set the ItemsSourceBidning directly to "Countries" - ItemsSourceBingind={Binding Countries}".
 

Best wishes,
Maya
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
Ubuntu
Top achievements
Rank 1
answered on 27 Apr 2011, 01:00 PM
Hello Maya,
I assure you that this scenario is not working because:

I have two QDSCV to hold my RadGridView source and the GridViewComboBoxColumn defined at my VM if I use the following ItemsSourceBinding="{Binding AccountCollection}" for the GridViewComboBoxColumn it doesn't show up the data unless I use the DataContextProxy as a resource in my view model.

Regards
0
Maya
Telerik team
answered on 27 Apr 2011, 02:49 PM
Hi,

I am sending you a sample project illustrating the usage of ItemsSourceBinding. Please take a look at it and let me know whether you have implement it similarly or you have additional settings or requirements.
 

Kind regards,
Maya
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
Ubuntu
Top achievements
Rank 1
answered on 28 Apr 2011, 04:00 PM
Hello Maya,

As I said before you can't have the binding works without this part in the xaml:
<UserControl.Resources>
    <my:MyViewModel x:Key="MyViewModel"/>
</UserControl.Resources>

Which means that you need to have the ViewModel as a resource in XAML.or to have somthing like DataContextProxy.

Thanks


Tags
GridView
Asked by
George
Top achievements
Rank 1
Answers by
Maya
Telerik team
George
Top achievements
Rank 1
Ubuntu
Top achievements
Rank 1
Share this question
or