(I know that I've asked this question before, but honestly the search tools for this latest version of MSDN Forums lacks some to be desired. Why, for example, does it appear to only show me questions I've asked or answered, going no further back than 6 months ago? I've asked/answered questions further back than that, and would like to have access to those questions.)
So now, to continue to ask the question I've asked before but can't find, here's the situation. I've got a data grid on a window. It's bound to a table pointed to by the CollectionViewSource aSIDrugAlcoholASISubstanceUsesViewSource (I'll provide the XAML later). One of the columns in this table is SubstanceType. Since the other 3 columns (ClientNumber, CaseNumber and Followup) are all hidden from the user, they all have the same values because previously that was selected elsewhere. ClientNumber, CaseNumber, Followup and SubstanceType together comprise the primary key of the table. Therefore, SubstanceType cannot be duplicated for the client/case and follow-up numbers. Right now what I've got is a DataGridComboBox which displays values that are taken from a lookup table pointed to by the CollectionViewSource names aSICodesSubstanceTypeViewSource. I don't filter what's shown, just always show all of the items from the lookup table. This is OK, so long as the user is careful and doesn't select a substance that he/she has previously selected. However, users are going to most likely accidentally select some substance they've already selected, and then when my app tries to put it into the database, it fails. So what I need is a way of making sure that a user cannot select a duplicate substance, given what they've already selected for that client/case and follow-up. How do I do that, please?
Here's the XAML for the DataGrid:
<Grid DataContext="{StaticResource aSIDrugAlcoholASISubstanceUsesViewSource}" DockPanel.Dock="Top" Margin="100,30,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"><DataGrid x:Name="aSISubstanceUsesDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" CanUserAddRows="True" Height="175" MinWidth="400" FontSize="16" RowDetailsVisibilityMode="VisibleWhenSelected"><DataGrid.Resources><SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGray" /></DataGrid.Resources><DataGrid.Columns><DataGridTextColumn x:Name="clientNumberColumn" Binding="{Binding ClientNumber}" Visibility="Collapsed" Header="Client Number" Width="SizeToHeader"/><DataGridTextColumn x:Name="caseNumberColumn" Binding="{Binding CaseNumber}" Visibility="Collapsed" Header="Case Number" Width="SizeToHeader"/><DataGridTextColumn x:Name="followupColumn" Binding="{Binding Followup}" Visibility="Collapsed" Header="Followup" Width="SizeToHeader"/><DataGridComboBoxColumn x:Name="substanceTypeColumn" Width="Auto" SelectedValueBinding="{Binding SubstanceType}" ItemsSource="{Binding Source={StaticResource aSICodesSubstanceTypeViewSource}}" DisplayMemberPath="SubstanceDesc" SelectedValuePath="SubstanceType" CellStyle="{StaticResource DataGridCellForeground}" Header="Substance"><DataGridComboBoxColumn.HeaderStyle><Style TargetType="{x:Type DataGridColumnHeader}"><Setter Property="HorizontalAlignment" Value="Center" /><Setter Property="BorderBrush" Value="Transparent" /></Style></DataGridComboBoxColumn.HeaderStyle></DataGridComboBoxColumn><DataGridTemplateColumn x:Name="ageOfFirstUseColumn" Width="SizeToHeader"><DataGridTemplateColumn.Header><StackPanel><TextBlock HorizontalAlignment="Center">Age of</TextBlock><TextBlock HorizontalAlignment="Center">First Use</TextBlock></StackPanel></DataGridTemplateColumn.Header><DataGridTemplateColumn.CellTemplate><DataTemplate><telerik:RadMaskedNumericInput Mask="###" BorderThickness="0" HorizontalAlignment="Center" Background="Transparent"><telerik:RadMaskedNumericInput.Value><Binding Path="AgeOfFirstUse"><Binding.ValidationRules><local:ByteValidation ErrorMessage="Value must be between 0 and 255" /></Binding.ValidationRules></Binding></telerik:RadMaskedNumericInput.Value></telerik:RadMaskedNumericInput></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridComboBoxColumn x:Name="routeColumn" Width="Auto" SelectedValueBinding="{Binding Route}" ItemsSource="{Binding Source={StaticResource aSICodesRouteViewSource}}" DisplayMemberPath="RouteDescription" CellStyle="{StaticResource DataGridCellForeground}" SelectedValuePath="Route" Header="Route"><DataGridComboBoxColumn.HeaderStyle><Style TargetType="{x:Type DataGridColumnHeader}"><Setter Property="HorizontalAlignment" Value="Center" /><Setter Property="BorderBrush" Value="Transparent" /></Style></DataGridComboBoxColumn.HeaderStyle></DataGridComboBoxColumn><DataGridTemplateColumn x:Name="lifeUseYearsColumn" Width="SizeToHeader"><DataGridTemplateColumn.Header><StackPanel><TextBlock HorizontalAlignment="Center"># Years</TextBlock><TextBlock HorizontalAlignment="Center">Used</TextBlock></StackPanel></DataGridTemplateColumn.Header><DataGridTemplateColumn.CellTemplate><DataTemplate><telerik:RadMaskedNumericInput Mask="###" BorderThickness="0" HorizontalAlignment="Center" Background="Transparent"><telerik:RadMaskedNumericInput.Value><Binding Path="LifeUseYears"><Binding.ValidationRules><local:ByteValidation ErrorMessage="Value must be between 0 and 255" /></Binding.ValidationRules></Binding></telerik:RadMaskedNumericInput.Value></telerik:RadMaskedNumericInput></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTemplateColumn x:Name="daysUseLast30Column" Width="SizeToHeader"><DataGridTemplateColumn.Header><StackPanel><TextBlock HorizontalAlignment="Center"># Days Used</TextBlock><TextBlock HorizontalAlignment="Center">in Last 30</TextBlock></StackPanel></DataGridTemplateColumn.Header><DataGridTemplateColumn.CellTemplate><DataTemplate><telerik:RadMaskedNumericInput Mask="###" BorderThickness="0" HorizontalAlignment="Center" Background="Transparent"><telerik:RadMaskedNumericInput.Value><Binding Path="DaysUseLast30"><Binding.ValidationRules><local:ByteValidation ErrorMessage="Value must be between 0 and 255" /></Binding.ValidationRules></Binding></telerik:RadMaskedNumericInput.Value></telerik:RadMaskedNumericInput></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid></Grid>
Rod