Click here to Skip to main content
14,739,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following data bound ComboBox, and it insists on automatically selecting the last item when loaded. Anyway to get it to load with nothing selected?

<ComboBox Name="ComboBoxResourceAdd" IsEditable="False" IsReadOnly="True" SelectedValue="" ItemsSource="{Binding Mode=OneWay, RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ResourcesView}" DisplayMemberPath="Name" SelectedValuePath="ID"/>


To be clear, I am only trying to populate the dropdown choices for the user, not bind the selection back to any object.

What I have tried:

I have tried placing SelectedValue = "" before and after the ItemsSource property set. When I place SelectedIndex = "0" it will successfully select the first item instead of the last, but when I try SelectedIndex = "-1" it goes back to automatically selecting the last item. Any help appreciated.
Posted
Updated 4-Jun-20 13:39pm
v3

1 solution

Sorry for the trouble. Found the solution:

The ResourcesView used to populate the list was in use in other places in the application, and was synching all controls bound to it.

So setting the IsSynchronizedWithCurrentItem=False on all the ComboBoxes that were using it in this read-only manner was needed. Other list controls elsewhere need the synchronization.
   

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