-3

I want to block user to edit/select combobox. I tried using cmbbox.IsReadOnly = True and cmbbox.IsEditable = False which allows user to change selection by alt and arrow' keys. cmbbox.isEnabled = False works and my requirement is to change combobox foreground color to 'Black' when it is disabled. Can anyone please help me to fix it?

In XAML:

<telerik:RadComboBox Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2"  x:Name="combobox1" IsEditable="True" IsFilteringEnabled="True" ItemsSource="{Binding}" TabIndex="7" Style="{ DynamicResource DropDownListStyle }" IsTabStop="True" KeyboardNavigation.TabNavigation ="Local" SelectAllTextEvent="None" Height="23" Margin="0,0,0,2" VerticalAlignment="Center"/>

In Codebehind:

combobox1.IsEnabled = False

In Style:

 <Style x:Name="DropDownListStyle" x:Key="DropDownListStyle" TargetType="telerik:RadComboBox" >
                <Setter Property="Foreground" Value="#FF000000"/>
                <Setter Property="BorderBrush" Value="#ffcccccc"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="HorizontalContentAlignment" Value="Left" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="FontWeight" Value="Thin"/>
                <Setter Property="FontFamily" Value="Trebuchet MS"/>
                <Setter Property="Panel.ZIndex" Value="10" />
                <Setter Property="Height" Value="23" />
                <!--  <Setter Property="Focusable" Value="True"/> -->
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="White"/>
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
M-O
  • 1
  • 5
  • Please share some of your code – wake-0 Jun 17 '16 at 07:49
  • Indeed it would be nice to edit your question and add the code you've written so far : [How to create a Minimal, Complete, and Verifiable example ?](http://stackoverflow.com/help/mcve). – Ivan Gabriele Jun 17 '16 at 08:10

2 Answers2

0

If you want prevent the user changing this combo box without using ReadOnly or Enabled you could try this on the Combo Box SelectedIndexChanged Event.

But without seeing your code we can't help on the particular issue.

'Inform the user
MsgBox("You can't change this drop down")
'Reset any choice
e.NewValue = e.CurrentValue

e is the event arguments that get passed in when choosing the selected index changed event.

Ryan Thomas
  • 1,724
  • 2
  • 14
  • 27
0

I have fixed it by setting IsReadonly = True property to combobox and triggering PreviewKeyDown event.

combobox1.IsReadonly = True

and

Private Sub combobox1_PreviewKeyDown(sender As Object, e As Windows.Input.KeyEventArgs) Handles combobox1.PreviewKeyDown
        If combobox1.IsReadOnly Then
            If e.Key = Key.Tab Then
                e.Handled = False
            Else
                e.Handled = True
            End If
        End If
End Sub
M-O
  • 1
  • 5