Hi Telerik-team,
Is it possible to select what columns should be shown in the dropdown from the GridViewMultiColumnComboBoxColumn, like it is possible in the RadMultiColumnComboBox? I could not find any documentation on that.
Thank you in advance!
Greetings, Mats
5 Answers, 1 is accepted
Hi Mats,
The recommended approach when further customizations to the RadMultiColumnComboBox in the column are required is to use the CellEditTemplate of the column and define the control there. Here's an example:
<telerik:GridViewDataColumn DataMemberBinding="{Binding MaterialType}">
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadMultiColumnComboBox>
<telerik:RadMultiColumnComboBox.ItemsSourceProvider>
<telerik:GridViewItemsSourceProvider ItemsSource="{Binding Materials}">
<telerik:GridViewItemsSourceProvider.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Id}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
</telerik:GridViewItemsSourceProvider.Columns>
</telerik:GridViewItemsSourceProvider>
</telerik:RadMultiColumnComboBox.ItemsSourceProvider>
</telerik:RadMultiColumnComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
We do have an open feature request for a DropDownEditorStyle to allow such customizations for which you can vote here.
If your requirement is to do this dynamically, at this point, you can handle the PreparedCellForEdit event of the parent RadGridView control in a similar manner:
private void RadGridView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
// you can also check the column through the e.Column property
var mccb = e.EditingElement as RadMultiColumnComboBox;
if (mccb != null)
{
var provider = mccb.ItemsSourceProvider as GridViewItemsSourceProvider;
provider.AutoGenerateColumns = false;
provider.Columns.Add(new GridViewDataColumn() { DataMemberBinding = new Binding("Id") });
provider.Columns.Add(new GridViewDataColumn() { DataMemberBinding = new Binding("Name") });
}
}
Please let me know whether using the CellEditTemplate or the PreparedCellForEdit event will work for you.
Regards,
Dilyan Traykov
Progress Telerik
CellEditTemplate worked for me. How can i change the displayed name for the GridViewDataColumn like i do for the RadMultiColumnComboBox? The selected value is by a Guid and the displayed name should be a different one
Regargs,
Mats
Hello Mats,
You can set the DisplayMemberPath of the RadMultiColumnComboBox to change the property which will be displayed by the combo box.
<telerik:RadMultiColumnComboBox DisplayMemberPath="Name">
Regards,
Dilyan Traykov
Progress Telerik
Hi Dilyan,
in my case it displays the DisplayMemberPath 'DisplayName' until the cell is validated. Afterwards it shows the 'SelectedGuid' in the GridView.
My code snippet:
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding SelectedGuid}"
Header
=
"Alternative Item"
Width
=
"600"
>
<
telerik:GridViewDataColumn.CellEditTemplate
>
<
DataTemplate
>
<
telerik:RadMultiColumnComboBox
NullText
=
""
DisplayMemberPath
=
"DisplayName"
Style
=
"{StaticResource MultiColumnComboBoxStyle}"
SelectedValuePath
=
"ID"
SelectedValue
=
"{Binding SelectedGuid}"
SelectedItem
=
"{Binding SelectedItemVariant}"
>
<
telerik:RadMultiColumnComboBox.ItemsSourceProvider
>
<
telerik:GridViewItemsSourceProvider
ShowColumnHeaders
=
"False"
RowIndicatorVisibility
=
"Collapsed"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding Source={StaticResource ItemVariants}}"
>
<
telerik:GridViewItemsSourceProvider.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Item}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Description}"
/>
</
telerik:GridViewItemsSourceProvider.Columns
>
</
telerik:GridViewItemsSourceProvider
>
</
telerik:RadMultiColumnComboBox.ItemsSourceProvider
>
</
telerik:RadMultiColumnComboBox
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellEditTemplate
>
</
telerik:GridViewDataColumn
>
Regards,
Mats
Hi Mats,
This result is expected because you've only redefined the CellEditTemplate of the column. When the editing process is done, the default CellTemplate will be used - a standard TextBlock whose Text property is bound to the property set as the DataMemberBinding of the column. This is why you observe the SelectedGuid once the cell is validated.
To achieve your requirement, you can use a LookupElement in the CellTemplate of the column, like so:
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:LookupElement
SelectedValue="{Binding SelectedGuid}"
ItemsSource="{Binding Source={StaticResource ItemVariants}"
DisplayMemberPath="DisplayName"
SelectedValuePath="ID" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
Regards,
Dilyan Traykov
Progress Telerik