Databind combobox columns in a gridview which has dynamic data as item source

0 Answers 29 Views
ComboBox GridView
Stefan
Top achievements
Rank 1
Stefan asked on 23 Nov 2023, 02:02 PM

Hi,

We have an old application (VB6) that we are migrating to WPF and .NET 8. I use your WPF controls in this application. We use this application to creat test templates for different instruments.
Each test template consists of one or more subtest templates. Each subtest template consists of a test grid with different number of rows and columns, depending of instrument and type of test.
The subtest template grids data is stored in a database. Each subtest are stored in one table, each column number is stored in one table with foreign key to the subtest table, each cells value and row number is stored in one table with foreign key to the column table.  

So far I have managed read data to my gridview with the help of your article https://docs.telerik.com/devtools/wpf/controls/radgridview/how-to/use-mixed-clr-dlr-properties.

First question,
I want the 4 first rows to be comboboxes, different combobox data for each row. I have been able to get comboboxes with DataTempletSelector, DataTemplate and RadGridView_AutoGeneratingColumn,
with help from this forum post from Petar Mladenov https://www.telerik.com/forums/unable-to-use-datatemplates-with-gridview-dynamic-data-not-even-with-icustomtypeprovider.
But my problem is that I don't get any data in the comboboxes. So how should I define my combobox so it databinds to my collection of comboboxdata? 

Second question,
If I manage to fill the comboxes with data I don't know how to databind selectedvalue to my ObservableCollection<MyDataRow>, so how can I do that?
The rest of the gridcells are textboxes and they databinds automatically and updates my ObservableCollection<MyDataRow> when I change a value in a cell.

This is my gridview,

                    <telerik:RadGridView  x:Name="TestCasesGridView"
                                          ItemsSource="{Binding SubtestTestCases, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, BindsDirectlyToSource=True}"
                                          IsFilteringAllowed="False"
                                          CanUserSortColumns="False"
                                          ShowColumnHeaders="True"
                                          ShowSearchPanel="True"
                                          SearchMode="MatchAllTerms"
                                          SearchPanelCloseButtonVisibility="Collapsed"
                                          IsSynchronizedWithCurrentItem="False"
                                          AutoGenerateColumns="True"
                                          AutoGeneratingColumn="RadGridView_AutoGeneratingColumn"
                                          Margin="10"
                                          IsReadOnly="False"
                                          ShowGroupPanel="False"
                                          RowIndicatorVisibility="Collapsed"
                                          Height="Auto"
                                          Width="Auto"
                                          ScrollMode="Deferred"
                                          ClipboardCopyMode="Default"
                                          ClipboardPasteMode="AllSelectedRows"
                                          SelectionMode="Single"
                                          SelectionUnit="FullRow"
                                          ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                          ScrollViewer.VerticalScrollBarVisibility="Auto"
                                          CanUserSelectColumns ="False"
                                          GroupRenderMode="Flat">
                    <telerik:RadGridView.Columns>
                        <helper:MyColumn Header="#"
Width="30" TextAlignment="Center"/>
                    </telerik:RadGridView.Columns>
                    <telerik:RadGridView.Resources>
                        <helper:MyCellTemplateSelector x:Key="myCellTemplateSelector">
                            <helper:MyCellTemplateSelector.ColumnNames>
                                <DataTemplate>
                                    <telerik:RadComboBox ItemsSource="{Binding ColumnNames}" DisplayMemberPath="KBE_Ben" OpenDropDownOnFocus="True"/>
                                </DataTemplate>
                            </helper:MyCellTemplateSelector.ColumnNames>
                            <helper:MyCellTemplateSelector.ColumnUnit>
                                <DataTemplate>
                                    <telerik:RadComboBox ItemsSource="{Binding ColumnUnits}" DisplayMemberPath="KEN_Kod" OpenDropDownOnFocus="True"/>
                                </DataTemplate>
                            </helper:MyCellTemplateSelector.ColumnUnit>
                            <helper:MyCellTemplateSelector.ColumnInfo>
                                <DataTemplate>
                                    <telerik:RadComboBox ItemsSource="{Binding ColumnInfos}" DisplayMemberPath="INF_InfoRad" OpenDropDownOnFocus="True"/>
                                </DataTemplate>
                            </helper:MyCellTemplateSelector.ColumnInfo>
                            <helper:MyCellTemplateSelector.ColumnProperty>
                                <DataTemplate>
                                    <telerik:RadComboBox ItemsSource="{Binding ColumnProperties}" DisplayMemberPath="KEG_Namn" OpenDropDownOnFocus="True"/>
                                </DataTemplate>
                            </helper:MyCellTemplateSelector.ColumnProperty>
                        </helper:MyCellTemplateSelector>
                    </telerik:RadGridView.Resources>
                </telerik:RadGridView>

 

Stefan
Top achievements
Rank 1
commented on 24 Nov 2023, 01:36 PM

I have created support ticket, 1632261, for this question. I will post any answers here.

/Stefan

Stefan
Top achievements
Rank 1
commented on 30 Nov 2023, 02:22 PM

Hi,

To solve my problem I got attached project from Telerik.

/Stefan

Martin Ivanov
Telerik team
commented on 30 Nov 2023, 02:33 PM

Hey Stefan, thanks for sharing your solution with the community.

No answers yet. Maybe you can help?

Tags
ComboBox GridView
Asked by
Stefan
Top achievements
Rank 1
Share this question
or