EManning EManning - 1 month ago 17
Vb.net Question

Property bound to radcombobox not updated after item selected

After selecting an item from a combobox, the property attached does not get updated as expected. It's a noob error but I'd like to know what I'm doing wrong, please.

XAML:

<telerik:RadComboBox x:Name="cboFinish" ItemsSource="{Binding}" Text="{Binding finish}" TextSearch.TextPath="theFinish" IsEditable="True" >


Property:

Private _finish As String
Public Property finish As String
Get
Return _finish
End Get
Set(value As String)
_finish = value
NotifyPropertyChanged("finish")
End Set
End Property


In the dropdown closed event of the combo, I have to assign the property the value of cboFinish.Text to update the property to the new selection. This code shouldn't need to be done, does it?

thisOrderFinish.finish = cboFinish.Text

I thought that was the job of INotifyPropertyChanged.

Comboboxes seem to be the only control where I've noticed this behavior. Textbox properties updated as expected.

Thanks for your help.

Answer

The Text property of a ComboBox isn't the best choice for retrieving the selected value.

Depending on the Items in the Collection you should use:

  • SelectedItem : when the Items in the Collection are strings
  • SelectedValue : when the type of the Items is 'SomeClass'. ComboBox showing the same property for each Item. This property path is set with SelectedValuePath.

Each of the 4 possibilities in the tutorial stand on their own (you shouldn't combine them).

You probably want SelectedItem

<telerik:RadComboBox 
    ItemsSource="{Binding}" 
    SelectedItem="{Binding finish}"/>