I need a DataGridComboBoxColumn which should allow multiple selection. To do this, I created a DataGridComboBoxColumn populated with CheckBoxes. I handle the Checkbox selection through CommandManager.PreviewExecuted event selecting the check boxes based on stored strings separated by ';' My code:
if (((DataGrid)sender).CurrentCell.Column.DisplayIndex == 6)
{
DataGridRow row = (DataGridRow)SupplierProductsGrid.ItemContainerGenerator.ContainerFromIndex(SupplierProductsGrid.SelectedIndex);
DataGridCell RowColumn = SupplierProductsGrid.Columns[6].GetCellContent(row).Parent as DataGridCell;
ComboBox cb = RowColumn.Content as ComboBox;
if (cb != null)
{
Debug.WriteLine("Entered Combobox editing");
ComboBoxFill(cb, true);
}
}
and in CellEditEnding event I create a string based on the checked box items and store that back to table. My code for that is:
DataGridRow row = (DataGridRow)SupplierProductsGrid.ItemContainerGenerator.ContainerFromIndex(SupplierProductsGrid.SelectedIndex);
DataGridCell RowColumn = SupplierProductsGrid.Columns[6].GetCellContent(row).Parent as DataGridCell;
ComboBox cb = RowColumn.Content as ComboBox;
if (cb != null)
{
//Debug.WriteLine("Entered Combobox Consolidation");
ComboBoxFill(cb, false);
return;
}
The code for checking the comboBox CheckBox items from string and collating the checked items back to string is handled by ComboBoxFill method which works fine. No issue there. I am able to save to the table and retrieve the values. However unless the user select the combobox there is no way user knows what has been selected. I have a previous DataGridTextColumn which provides feedback. I would like to have both the DataGridTextColumn and DataGridComboBoxColumn in one column or a better approach to use multiple select DataGridComboBoxColumn
My Partial XAML looks like this. Of interest is MaterialType Text column and MaterialType combo column. I need to have this under one column so it will be more user friendly.
<DataGridTextColumn Binding="{Binding SupplierLeadTime}" Header="Lead Time" Width="1*" />
<DataGridComboBoxColumn x:Name="StorageUnitCombo" Header="Package Unit" SelectedValuePath="StorageUnitId" Width="2.5*"
DisplayMemberPath="Description" SelectedItemBinding="{Binding BaseStorageUnitNavigation}" />
<DataGridTextColumn x:Name="Materialtype" Header="Material Type" Width="140" Binding="{Binding MaterialType}" Visibility="Visible" ElementStyle="{StaticResource WT}" IsReadOnly="True"/>
<DataGridComboBoxColumn x:Name="MTCombo" Header="Material Type Combo" Width="140" ItemsSource="{Binding Source={StaticResource MaterialTypeViewSource}}" />
Any Help will be greatly appreciated.