Click here to Skip to main content
16,020,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 combo boxes addCC_cmbCollected & addCC_cmbQuality. Depending on the item selected in addCC_cmbCollected which is either Yes or No I want to disable the other combo box (addCC_cmbQuality) and select a particular item from this combo box, as I am storing the values to an XML and I want that if this is disabled the default value would be "NA" instead of showing the latest value when this was enabled.

XML
<ComboBox x:Name="addCC_cmbQuality" Grid.Column="7" HorizontalAlignment="Left" Margin="214,260,0,0" VerticalAlignment="Top" Width="111" RenderTransformOrigin="0.423,0.409" Height="23" Loaded="cmbQuality_Loaded">
    <ComboBox.Style>
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="IsEnabled" Value="True" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=SelectedValue, ElementName=addCC_cmbCollected}" Value="No">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ComboBox.Style>
</ComboBox>


What I have tried:

I have managed to disable the addCC_cmbQuality combobox but cannot find a way to show a particular value/item.
Posted
Updated 26-Mar-16 12:38pm

1 solution

Try something like this (I used a couple of buttons to toggle between enabled/disabled - you will probably want this in the OnSelectionChanged event)
C#
private void Disable_Click(object sender, RoutedEventArgs e)
{
    Job.Items.Add("NA");
    Job.SelectedValue = "NA";
    Job.IsEnabled = false;
}
private void Enable_Click(object sender, RoutedEventArgs e)
{
    Job.Items.Remove("NA");
    Job.IsEnabled = true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900