As i mentioned in my other post, I'm currently in the process of evaluating the RadGridView for our business.
We're using the Model-View-ViewModel pattern in our applications and when two objects are related, we store a reference to the other object instead of it's Id.
This thread explained how to get a GridViewComboBoxColumn working with related objects, but i can't get the ItemSource to bind to a collection on my ViewModel.
From what i can tell i can't use the ItemsSourceBinding property because, while it can be bound, its looking at the data item for that row and not the current DataContext. And i can't use the ItemsSource because it cannot be bound.
Is there anyway i can resolve this??
9 Answers, 1 is accepted
Hi Andrej ,
Initially the ItemsSourceBinding property was intended to bind to properties within the business object only. However we have recieved many requests ( such as yours) and have decided to expand the scope of the property.
In your other thread (about a tooltip ) I have recommended to take the latest internal build. The same here - shortly after the release we have removed the limit of the ItemsSourceBinding property and now you can bind to your view model.
Here is some working code I have recently sent to a client with a simillar request :
<
Grid
x:Name
=
"LayoutRoot"
>
<
Grid.Resources
>
<
local:ViewModel
x:Key
=
"AccountMaintenanceViewModel"
/>
</
Grid.Resources
>
<
gridview:RadGridView
x:Name
=
"gridview"
AutoGenerateColumns
=
"False"
ShowGroupPanel
=
"False"
Margin
=
"0,4,0,4"
RowIndicatorVisibility
=
"Collapsed"
Grid.Row
=
"1"
Grid.Column
=
"0"
Grid.ColumnSpan
=
"2"
IsEnabled
=
"{Binding IsAccountMaintenanceEditable}"
ItemsSource
=
"{Binding ObservableAccountMappingsByHierarchy}"
DataContext
=
"{Binding Source={StaticResource AccountMaintenanceViewModel}}"
>
<
gridview:RadGridView.Columns
>
<
gridview:GridViewComboBoxColumn
Header
=
"Mapping Target Account"
IsFilterable
=
"False"
ItemsSourceBinding
=
"{Binding AccountMappingOptions, Source={StaticResource AccountMaintenanceViewModel}}"
DisplayMemberPath
=
"Label"
Width
=
"*"
SelectedValueMemberPath
=
"ID"
DataMemberBinding
=
"{Binding ParentAccount, Mode=TwoWay}"
/>
</
gridview:RadGridView.Columns
>
</
gridview:RadGridView
>
</
Grid
>
Here the AccountMaintenanceViewModel is is holding the collection of items for the combo in its AccountMappingOptions property.
It is being set as a datacontext of the RadGridView and the combo box itemssource is bound in XAML.
Let me know if you need a working example or further assistance.
Best wishes,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Firstly, thank you very much for getting back to me. That works fine and is great news as far as binding support goes.
However, is filtering supported for a column configured in this way???
I was unable to get filtering to work (no filtering icon in column header) with my configuration, which looks like this:
<TelerikGrid:GridViewComboBoxColumn Header="Zone" |
IsFilterable="True" |
ItemsSourceBinding="{Binding Path=MyViewModel.Zones, Source={StaticResource ServiceLocator}}" |
DisplayMemberPath="Name" |
SelectedValueMemberPath="" |
DataMemberBinding="{Binding Zone, Mode=TwoWay}" /> |
The only thing i can think of is that my data item has a reference to its "Zone", hence the SelectedValueMemberPath="".
Thank you again for you're help so far. I look forward to hearing from you soon.
Andrej.
Hello Andrej ,
The problem here seems not to be in the combobox setup but more likely in the underlying data.
Filtering would not distinguish a custom type like the Zone type. Filtering UI is generated based on the type of the underlying object and when RadGridView meets the Zone object it will be impossible to recognize it and generate the respective filtering UI.
You may for example add another column bound to Zone.Name and use it for the purposes of filtering.
This is an ugly solution but is as close as we can get with the current solution.
An interesting idea emerges from your request - I will speak to the team if we can extend the filtering logic to use the DisplayMember path provided to feed the filtering engine with the correct data.
We are also considering to add a FilteringMemberPath property for the future to serve scenarios such as yours.
Regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I'm very glad that you at Telerik Silverlight Team supports M-V-VM design pattern which is becoming most used pattern worldwide.
We're also using the Model-View-ViewModel pattern in our applications and we appreciate your effort! Please keep going with MVVM pattern support!
Best wishes,
Matjaz
Stroka.si
Just wondering if there has been any development with regard to binding to an object and using the DisplayMemberPath or some other proeprty to make filtering and grouping work. I am now using the Q1 2010 release and still cannot acheive the desired behavior without a custom edit template.
There is still a way to go , but now we have the option to customize the filtering popup to be a better friend with the combobox column. You may have a peek on the approach at the this blogpost.
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.
with my example, it doesn't works...I don't undestand.
Here's my cod XAML
<
telerik:RadGridView
x:Name
=
"gvAppFunctions"
Height
=
"200"
RowIndicatorVisibility
=
"Collapsed"
AutoGenerateColumns
=
"False"
CanUserFreezeColumns
=
"False"
ShowGroupPanel
=
"False"
ShowColumnFooters
=
"False"
ItemsSource
=
"{Binding AppFunctions, Mode=TwoWay}"
SelectedItem
=
"{Binding SelectedAppFunction, Mode=TwoWay}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Valeur"
DataMemberBinding
=
"{Binding FunctionValue, Mode=TwoWay}"
Width
=
"100"
/>
<
telerik:GridViewComboBoxColumn
Width
=
"200"
Header
=
"Groupe"
DataMemberBinding
=
"{Binding GroupNameId, Mode=TwoWay}"
ItemsSourceBinding
=
"{Binding AppFunctionGroups, Source={StaticResource ViewModel}}"
DisplayMemberPath
=
"Groupname"
SelectedValueMemberPath
=
"Id"
>
</
telerik:GridViewComboBoxColumn
>
The problem: My combo seems to be filled but I do not see the item... As if the item were invisible
Thanking you in advance
Looking at the code-snippet you provided, I am not able to suggest on the reason for the items in the GridViewComboBoxColumn not to be displayed. So, in order to give you a possible solution, I would need more details about the ItemsSource of the grid and the column, more specifically about the exposed properties inside the classes.
Furthermore, you may take a look at this forum thread where you will find a sample project illustrating the implementation of the GridViewComboBoxColumn.
Maya
the Telerik team