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

MVVM ContainerBindingCollection approach for TreeView applies for GridView?

2 Answers 36 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 10 Apr 2011, 05:49 PM
Hi,

I'm wondering if the aproach of using ContainerBindingCollection to bind RadTreeItems properties to properties in the ViewModel data items and then using those properties to manage things like expanding, collapsing, selecting or putting items in edit mode could work for GridView.

I've tried to do it defining a DataTemplate, using a ConteinerBindingCollection resource defined in the XAML and then applying the DataTemplate to the ItemTemplate property of the GridView but it didn't work.

Any suggestion?

Regards

2 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 11 Apr 2011, 02:19 PM
Hi Adrian,

 
Due to the internal structure and logic of RadGridView there is no exact equivalent of the ContainerBindingCollection in the same way as it was implemented in RadTreeView. You may also bind the properties of RadGridView or GridViewColumns to the property value of the underlying business object.
For example if you need to disable the editing in particular rows based on a boolean property value you may use the following:


<telerik:RadGridView x:Name="radGridView1" IsReadOnlyBinding="{Binding IsActive,Mode=TwoWay}" .../>


You may also predefine the CellTemplate/CellEditTemplate for each GridViewColumn where you can predefine the default behavior and implement your own.  
Actually this is really wide topic to discuss and I would suggest you to review our online documentation where you may get the information you need, please follow this link.


Kind regards,
Vanya Pavlova
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
Adrian
Top achievements
Rank 1
answered on 27 Apr 2011, 05:22 AM
Hi Vanya, I appreciate your answer.
Let me explain better my question:
I'm trying to follow MVVM/Prism. In this context, the ViewModel don't need to know that the view is implementing display via RadGridView, buy just need to expose the data and a way to tell the View that some specific data item needs to change to edit mode.
In the case of TreeView this can be perfectly achieved by adding a property to the business object (IsInEditMode) and then use ContainerBindingCollection to bind that property to the one that puts TreeViewItem in edit mode. And as expected, the ViewModel don't know that I'm using RadTreeView to display the info, just work with business objects.
I'm not finding a way to achieve the same kind of behavior with GridView, without having to put some RadGridView specific code in the ViewModel (for example using RadGridViewCommands that is what I'm using now). I've read the documentation and the searched the forum but can't find the answer.
Maybe this could be achieved with other technique different from the one used with the TreeView, but as I mentioned I want to keep the ViewModel independent from the View implementation and find a way to put business objects in edit mode.

Regards
Adrian
Tags
GridView
Asked by
Adrian
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Adrian
Top achievements
Rank 1
Share this question
or