I trying to use a special DataTemplate for each data type of column in my grid:
e.g. a DataPicker for Dates, a string editor for strings, ..
I try to achive this by using a style selector, but my problem is that I can't bind the editor to the data of the cell/column.
All the examples I found always bind a Template to a specific column but not the column of the templated cell.
If I bind the template to a specific column "MyDataColA" like this, it works.
<
inh:CellEditTemplateSelector
x:Key
=
"cellEditTemplateSelector"
>
<
inh:CellEditTemplateSelector.DateTimeEditStyle
>
<
DataTemplate
>
<
telerik:RadDatePicker
SelectedValue
=
"{Binding MyDataColA, Mode=TwoWay}"
/>
</
DataTemplate
>
</
inh:CellEditTemplateSelector.DateTimeEditStyle
>
</
inh:CellEditTemplateSelector
>
But how to bind to the same column as the templated cell?
Is there a way to do this?
Regards
Thomas
5 Answers, 1 is accepted
Actually, by default the editor of GridViewDataColumn will depend on the type of the corresponding property and a RadDatePicker will be displayed when editing DateTime values for example. Furthermore, a CellEditTemplateSelector is used only for a single instance of a cell, you cannot define one CellEditTemplateSelector for all columns in the grid. May you clarify what is the purpose of trying to do so ?
Maya
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

I'm trying to define a set of 'special' column editor's e.g. a special editor for date-time, in a MVVM Environment.
The idea is to define this editors once as a template and select the current needed editor in a selector.
Like this (simplified) based on some criteria (might be data type only or data type and column name):
public
class
CellEditTemplateSelector : DataTemplateSelector {
public
override
DataTemplate SelectTemplate(
object
item, DependencyObject container){
GridViewCell cell = container
as
GridViewCell;
if
(cell !=
null
) {
GridViewBoundColumnBase col = cell.Column
as
GridViewBoundColumnBase;
if
(col !=
null
) {
if
(col.DataType ==
typeof
(
string
)) {
return
StringEditStyle;
}
else
if
(col.DataType ==
typeof
(DateTime)) {
return
DateTimeEditStyle;
}
}
}
return
null
;
}
public
DataTemplate StringEditStyle {
get
;
set
; }
public
DataTemplate DateTimeEditStyle {
get
;
set
; }
}
As the style selector is responsible for picking the right editor,
the editor could not be bound to specific column. So the binding syntax:
<telerik:RadDatePicker SelectedValue="{Binding MyDataColA
is not suitable in this case.
The question is, is there a syntax to bind this editor to the current column source, the editor
is applied for. (Something like "RelativeBinding").
Or if I'm doing something total strange, is there a better way of doing this?
Regards
Thomas
Actually, I am a bit confused here as to why you are trying to do this since RadGridView will do it automatically for you. May you clarify a bit on this, why do you need to handle such a scenario for defining editors for difference columns ?
Maya
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

the example with the simple string or DateTime editor was just a example. What I'm really trying is to have special editors for some kind of data, e.g. a editor that allows to pick data that's being retrieved by a sub query from the database with special filter options (not a simple dropdown list) or a very special input format that's not representable with a 'masked' editor, ...
Hope this helps to understand what was the aim of this.
Regards
Thomas
What you may do in this case is to create the template in xaml and handle it in the code-behind by replacing the binding with the corresponding property. This can be done in AutoGeneratingColumn event.
Another way to go is to use FrameworkElementFactory and define the corresponding template depending on the type of the underlying property.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>