How to get RadComboBox to default to no selection

0 Answers 26 Views
ComboBox
Johnathan
Top achievements
Rank 1
Iron
Iron
Johnathan asked on 07 May 2025, 10:00 PM

I've been pulling my hair out on this forever.  I'm developing an application that has items with custom fields.  Sometimes the user will choose an option from the custom field, sometimes they'll leave it blank.  I'm trying to get a RadComboBox to display the selected item only if the item is not null.  If the item is null, then the combobox should display nothing (or a notice it's blank).  

   What's happening is either the combobox does not keep in sync, or it defaults to the first item in the collection.  I need it to be in sync, but not default to the first item in the list if the property is null.  For example simplified view of my ViewModel:

Class CustomField:  Id as Integer, Description as String

ViewModel:

  Public Property Selection as CustomField
  Public Options as ObservableCollection(Of CustomField)

WPF:

        <telerik:RadComboBox x:Name="rcbDropDown" 
                             ItemsSource="{Binding Path=Options}"
                             SelectedValuePath="Id"
                             DisplayMemberPath="Choice"
                             SelectedItem="{Binding Path=Selection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             ClearSelectionButtonContent="Clear"
                             ClearSelectionButtonVisibility="Visible"
                             IsEditable="False"
                             IsReadOnly="{Binding Path=IsReadOnly}"
                             EmptyText="Not Set"
                             UpdateSelectionOnLostFocus="True"
                             />

I've tried multiple combinations of SelectedItem Mode=TwoWay, OneWayToSource and IsSyncronizedWithCurrentItem=True/False/NULL

   I either end up with them syncing and the combo box defaulting to the first item on the list automatically, and pushing that into the viewmodel when the record is viewed, or not syncing.  I can't get it to only show the selected item when it's not null.  Any help would be appreciated!

 

 

Martin Ivanov
Telerik team
commented on 12 May 2025, 01:19 PM

Hi Johnathan, I've tested the ComboBox, but couldn't recreate the described problem. Setting the selection to null seems to work as expected. Can you check the attached project and tell me what I am missing?

No answers yet. Maybe you can help?

Tags
ComboBox
Asked by
Johnathan
Top achievements
Rank 1
Iron
Iron
Share this question
or