I have the following DataGridTemplate column:
<DataGridTemplateColumn x:Name="specialtiesColumn" Header="Specialties" MinWidth="170"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding Path=DataContext.Specialties, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}}"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Height="17" VerticalAlignment="Center" Orientation="Horizontal"> <CheckBox Width="20"> <CheckBox.IsChecked> <MultiBinding Converter="{StaticResource ProviderSpecialtyIsInSpecialtiesConverter}"> <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=ComboBox}" Path="DataContext.Specialties" /> <Binding Path="Name" /> </MultiBinding> </CheckBox.IsChecked> </CheckBox> <TextBlock Text="{Binding Name}" Width="130" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>
What I'm trying to do is have a comboboxes column inside a datagrid, and there are several checkboxes in each combo box. Each row of data represents a hospital. The list box indicates which specialties the hospital has, and the user should also be able to change these parameters.
This is the code for the converter:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { try { HashSet<Specialty> specialties = (HashSet<Specialty>)values[0]; string specialty = (string)values[1]; foreach (Specialty s in specialties) { if (s.Name == specialty) return true; } return false; } catch (Exception) { return false; } }
This works on computers with .Net Framework 4.5, but it crashes when you try to download only with .Net Framework 4.0. The project is intended for the .NET Framework 4.0.
source share