wpftelerikradcombobox

RadCombobox property losing value between GotFocus and LostFocus


I have a radcombobox whose property loses it value somewhere between the GotFocus and LostFocus event.

XAML:

<telerik:RadComboBox x:Name="cboWoodSpecies" 
    FontSize="16"  Margin="0,4,0,0" Background="#F6F8FA" BorderBrush="#D7D8DD" 
    ItemsSource="{Binding}" Text="{Binding woodSpecies, Mode=TwoWay}" 
    telerik:TextSearch.TextPath="WoodSpecies" 
    IsEditable="True" IsReadOnly="True" TabIndex="0"
    Style="{DynamicResource RadComboBoxStyle3}" >

GotFocus event:

Private Sub cboWoodSpecies_GotFocus(sender As Object, e As RoutedEventArgs) Handles cboWoodSpecies.GotFocus

    BindComboBoxes.WoodSpecies(cboWoodSpecies)  'bind cbo to data


    If thisOrder.woodSpecies <> String.Empty Then   'Property OK here!!
        DisplayWoodSpeciesImage()
    End If
End Sub

DisplayWoodSpeciesImage reads the value of the property but does not reset it to Nothing.

LostFocus:

Private Sub cboWoodSpecies_LostFocus(sender As Object, e As RoutedEventArgs) Handles cboWoodSpecies.LostFocus

    If thisOrder.woodSpecies <> String.Empty Then   'Property = Nothing.  Why?!?!
        'do stuff
    End If

End Sub

I think it has something to do with the combobox itself. Selecting a new item from the combo does not cause the problem. It's filling the combo with existing data that causes the problem. I have to reselect the item to bypass the error.

That being said, is there a way to refresh the combobox so it thinks the item has been selected again? Is it something with SelectedItem that needs to be set?

Thanks for any help or advice.


Solution

  • Try to set the SelectedValuePath of the ComboBox to "WoodSpecies" and bind the SelectedValue (instead of the Text property) to "woodSpecies":

    <telerik:RadComboBox x:Name="cboWoodSpecies" 
    FontSize="16"  Margin="0,4,0,0" Background="#F6F8FA" BorderBrush="#D7D8DD" 
    ItemsSource="{Binding}"
    SelectedValuePath="WoodSpecies"
    SelectedValue="{Binding woodSpecies, Mode=TwoWay}" 
    telerik:TextSearch.TextPath="WoodSpecies" 
    IsEditable="True" IsReadOnly="True" TabIndex="0"
    Style="{DynamicResource RadComboBoxStyle3}" >