(see below my own answer, which I came up with after I missed this puncture for several days and days) I am trying to execute the following script in WPF.
I have a datagrid that displays data rows for viewing and entering additional data. This is a new application, but there is outdated data.
In one particular field in the past there was data accidentally entered into it. Now we want to limit the field values to a specific list. Therefore, I am using DataGridComboBoxColumn. FWIW I also tried this with a DataGridTemplateColumn containing a ComboBox.
At runtime, if an existing value is not in the list, I want it to be displayed anyway. I just can’t understand that this will happen. While I tried to use a lot of solutions (all failures), here is what is most logical as a starting point.
The list of values for the drop-down list is defined in a Windows resource called "months."
<DataGridComboBoxColumn x:Name="frequencyCombo" MinWidth="100" Header="Frequency" ItemsSource="{Binding Source={StaticResource months}}" SelectedValueBinding="{Binding Path=Frequency,UpdateSourceTrigger=PropertyChanged}"> <DataGridComboBoxColumn.ElementStyle> <Style TargetType="ComboBox"> <Setter Property="IsSynchronizedWithCurrentItem" Value="False" /> </Style> </DataGridComboBoxColumn.ElementStyle> </DataGridComboBoxColumn>
What happens is that if the value is not in the list, then the display is empty. At runtime, I checked that the IsSynchronizedWithCurrentItem element is indeed False. It just doesn't do what I expect.
Maybe I'm just going the wrong way. Maybe I need to use a text box in combination with combobox. Maybe I need to write code, not just XAML. I spent several hours trying different things and would be very grateful for the decision. I had a few suggestions for using this class or this control, but without explaining how to use it.
Thanks a bunch!
source share