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

GridViewMultiColumnComboBoxColumn not auto generate columns

5 Answers 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mats
Top achievements
Rank 1
Mats asked on 29 Oct 2019, 08:03 AM

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

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 31 Oct 2019, 12:32 PM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mats
Top achievements
Rank 1
answered on 05 Nov 2019, 10:43 AM

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

0
Dilyan Traykov
Telerik team
answered on 05 Nov 2019, 12:41 PM

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">
Please let me know if this is what you were looking for.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mats
Top achievements
Rank 1
answered on 05 Nov 2019, 01:46 PM

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

0
Accepted
Dilyan Traykov
Telerik team
answered on 06 Nov 2019, 04:04 PM

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>
Please give this a try and let me know if you manage to achieve the desired result.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Mats
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Mats
Top achievements
Rank 1
Share this question
or