Hi,
At the moment I'm facing an issue, I have a RadGridView which can show different tables with different definitions(not at the same time)
So AutoGenerateColumns is set to True.
now it can happen that some columns have an FK to another table.
Before I replaced those columns in the DataLoaded event but because of performance reasons I would like to do those replaces in the CurrentCellChanged event.
The problem when I do this is that the new GridViewComboBoxColumn misses the link to the actual datasource, and while reading the value for saving in the database, the value is DBNULL.
the gridview in de Xaml looks like this
<DataTemplate x:Key="AdminViewMainSectorTemplate"> <Grid Margin="10"> <Grid> <telerik:RadBusyIndicator x:Name="BusyIndicator" Grid.Row="2" > <telerik:RadGridView x:Name="gridViewAdminData" ItemsSource="{Binding DataRecords, Mode=TwoWay}" RowEditEnded="EditRecord" Deleted="deleteRecord" AddingNewDataItem="AddingNewDataItem" MinColumnWidth="100" ColumnWidth="*" NewRowPosition="Top" AutoGeneratingColumn="AutoGeneratingColumn" DataLoading="LoadData" DataLoaded="DataLoaded" CurrentCellChanged="CurrentCellChanged" SelectionUnit="Cell" > <!--DataLoading="LoadData" DataLoaded="DataLoaded"--> <telerik:EventToCommandBehavior.EventBindings> <telerik:EventBinding Command="{Binding HandleAddingNewRecordToDevicesGridCommand}" EventName="AddingNewDataItem" PassEventArgsToCommand="True"/> </telerik:EventToCommandBehavior.EventBindings> </telerik:RadGridView> </telerik:RadBusyIndicator> </Grid> </Grid> </DataTemplate>and my code behind looks like this:
private void CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e) { RadGridView rgv = (RadGridView)sender; GridViewCell cell = rgv.CurrentCell; if (cell != null && typeof(GridViewDataColumn) == cell.Column.GetType()) { Models.MyEntities db = new Models.MyEntities(); string tableName = Helpers.GlobalParameters.currenTableName; if (tableName =="batches") { string fieldname = cell.Column.UniqueName; if (fieldname == "ProductieOrderId") { int index = cell.Column.DisplayIndex; GridViewComboBoxColumn cbb = new GridViewComboBoxColumn(); cbb.DataMemberBinding = new System.Windows.Data.Binding(fieldname); //cbb.DataMemberBinding = cell.DataColumn.DataMemberBinding; cbb.ItemsSource = db.productieorder.ToList(); cbb.SelectedValueMemberPath = fieldname; cbb.DisplayMemberPath = "Id"; //cbb.Name = fieldname; cbb.UniqueName = fieldname; cbb.DisplayIndex = index; rgv.Columns.Remove(cell.Column); //rgv.Columns.Remove(cell.DataColumn); rgv.Columns.Add(cbb); } } else if (tableName =="artikel")If I do this
cbb.SelectedValueMemberPath = "Id";what I would say is logical, the shown value in the combobox stays empty.
does anyone know where to look to fix this issue?