
Hello
I am in vb.net with wpf, I have an existing radgridview with custom validationDiffProperty. I am using telerik v 2017.3.1018.45
My goal is to add a radgriview row with radcombox (see attach image). I know how to add a radcombobox column in a radgridview, but I don't know how to add a "radcombobox row" in a radgriview.
Could you please help me ?
Regards
Jean-Christophe
5 Answers, 1 is accepted
Thank you for the attached image.
I would recommend you to try using CellTemplateSelector property of the RadGridView columns. There is a CellTemplateSelector help article in our RadGridView documentation which further described this property. In your case, you can create one custom DataTemplateSelector class and applied to every column. Then you can just return the custom DataTemplate with RadComboBox inside only for the first cell.
Regards,
Dinko
Progress Telerik

Hello Dinko
Thanks for your information, I tried to adapt it a little bit because I can not use like it's descirbed in CellTemplateSelector
I add a new datatemplateselector class like below
Public
Class
DropDownCellTemplateSelector
Inherits
DataTemplateSelector
Public
Overrides
Function
SelectTemplate(item
As
Object
, container
As
DependencyObject)
As
DataTemplate
If
TypeOf
item
Is
MyObjectType
Then
Return
MyObjectDataTemplate
Else
Return
Nothing
End
If
End
Function
Public
Property
MyObjectDataTemplate()
As
DataTemplate
End
Class
I declared it in my xaml (see below)
<
UserControl.Resources
>
<
ResourceDictionary
>
<
templateSelector:DropDownCellTemplateSelector
x:Key
=
"DropDownCellTemplateSelector"
>
<
templateSelector:DropDownCellTemplateSelector.MyObjectDataTemplate
>
<
DataTemplate
>
<
telerik:RadComboBox
ItemsSource
=
"{Binding MyObjectList}"
DisplayMemberPath
=
"Name"
/>
</
DataTemplate
>
</
templateSelector:DropDownCellTemplateSelector.MyObjectDataTemplate
>
</
templateSelector:DropDownCellTemplateSelector
>
...
...
...
and I added it to my columns using behind code of the xaml because column are dynamically built (see below)
Private
Sub
GridViewDataControlOnAutoGeneratingColumn(sender
As
Object
, e
As
GridViewAutoGeneratingColumnEventArgs)
If
(e.Column.UniqueName =
"TitleColumn"
)
Then
e.Column.Width = TITLE_WIDTH
e.Column.IsReadOnly =
True
Else
e.Column.Width = COLUMN_WIDTH
e.Column.CellEditTemplateSelector=
CType
(
Me
.Resources(
"DropDownCellTemplateSelector"
), Controls.DataTemplateSelector)
Dim
binding =
New
Binding(
"IsInEditMode"
)
binding.Converter =
Me
._invertedBooleanConverter
e.Column.SetBinding(GridViewColumn.IsReadOnlyProperty, binding)
End
If
End
Sub
But I have a pb because the method SelectTemplate of DropDownCellTemplateSelector is never hit, do you have an idea ?
Thank
an-Christophe

Never mind about my previous post, I made a mistake, I wrote CellEditTemplateSelector instead of CellTemplateSelector, now the radcombobox appear but they are not populate, whereas the list is well filled, and raisePropertyChanged event raised.
Do you know if some trouble coule appear with radcombobox in radgridview ?
Thanks
Regards
Jean-Christophe

Hello Dinko
Thanks for all, it works, the only thing which doesn't work yet is the assignation of combobox value when radgridview is populated, but I think it's because I use personnal validationDifProperty.
If somemone needs to do the same thing, below you could find the code :
datatemplateSelector class :
01.
Public
Class
DropDownCellTemplateSelector
02.
Inherits
DataTemplateSelector
03.
04.
Public
Overrides
Function
SelectTemplate(item
As
Object
, container
As
DependencyObject)
As
DataTemplate
05.
If
TypeOf
item
Is
MyObjectType
Then
06.
Return
MyObjectDataTemplate
07.
Else
08.
Return
Nothing
09.
End
If
10.
End
Function
11.
12.
Public
Property
MyObjectDataTemplate()
As
DataTemplate
13.
14.
End
Class
xaml file :
01.
<
UserControl.Resources
>
02.
<
ResourceDictionary
>
03.
<
templateSelector:DropDownCellTemplateSelector
x:Key
=
"DropDownCellTemplateSelector"
>
04.
<
templateSelector:DropDownCellTemplateSelector.MyObjectDataTemplate
>
05.
<
DataTemplate
>
06.
<
telerik:RadComboBox
ItemsSource
=
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.MyObjectList}"
DisplayMemberPath
=
"Name"
SelectedValuePath
=
"Id"
IsEnabled
=
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.IsInEditMode}"
/>
07.
</
DataTemplate
>
08.
</
templateSelector:DropDownCellTemplateSelector.MyObjectDataTemplate
>
09.
</
templateSelector:DropDownCellTemplateSelector
>
10.
...
11.
...
12.
...
xaml.vb :
01.
Private
Sub
GridViewDataControlOnAutoGeneratingColumn(sender
As
Object
, e
As
GridViewAutoGeneratingColumnEventArgs)
02.
If
(e.Column.UniqueName =
"TitleColumn"
)
Then
03.
e.Column.Width = TITLE_WIDTH
04.
e.Column.IsReadOnly =
True
05.
Else
06.
e.Column.Width = COLUMN_WIDTH
07.
e.Column.CellTemplateSelector=
CType
(
Me
.Resources(
"DropDownCellTemplateSelector"
), Controls.DataTemplateSelector)
08.
Dim
binding =
New
Binding(
"IsInEditMode"
)
09.
binding.Converter =
Me
._invertedBooleanConverter
10.
e.Column.SetBinding(GridViewColumn.IsReadOnlyProperty, binding)
11.
End
If
12.
13.
End
Sub
Regards
J-Christophe
I have created a sample project which demonstrates how you can populate the RadComboBox in the first cell of a column. My understanding is that you are struggling with binding the SelectedItem property of every combo box control. After investigating on my side I think I manage to found a possible approach. What you can do is to create a property for every ComboBox in the RadGridView business object. Then you can use bind the SelectedItem property of the RadComboBox to the GridViewCell using RelativeSource and set an IValueConverter class. In the Convert method, you can check the column header and create the binding depending on the name. Check the attached project. When you open the project you can add breakpoints in the setter of the CustomerNameComboBoxValue and CustomerIDComboBoxValue which is fired when you select an item from the comboboxes.
Regards,
Dinko
Progress Telerik