qqus
qqus

Reputation: 493

How to set the value of the SelectedItem property in devexpress combobox BarItem?

It is example Combobox in which everything is working good and selected value varies depending on changes CurrentPlanSet.

       <dxe:ComboBoxEdit ItemsSource="{Binding PlanSets, Mode=TwoWay}" 
                               DisplayMember="Name" 
                               ValueMember="Name"
                               SelectedItem="{Binding CurrentPlanSet, Mode=TwoWay}"
                               />

In this example the selected value does not change depending on CurrentPlanSet changes.

<dxb:BarEditItem Content="Plan Sets" EditWidth="350">
                <dxb:BarEditItem.EditStyle>
                    <Style TargetType="{x:Type dxe:ComboBoxEdit}">
                        <Setter Property="SelectedIndex" Value="{Binding     CurrentPlanSet, Mode=TwoWay}"/>
                    </Style>
                </dxb:BarEditItem.EditStyle>
                <dxb:BarEditItem.EditSettings  >
                    <dxe:ComboBoxEditSettings ItemsSource="{Binding PlanSets, Mode=TwoWay}" ValueMember="Id" DisplayMember="Name" />
                </dxb:BarEditItem.EditSettings>
            </dxb:BarEditItem>

How to correctly set the value of the SelectedItem property in second code example?

Upvotes: 0

Views: 1182

Answers (1)

Frerk Morrin
Frerk Morrin

Reputation: 729

SelectedIndex is not the same as SelectedItem. This is the same as with the default WPF Controls.

SelectedIndex is the Index of the CollectionItem, you have selected/set selected (Integer). The SelectedItem is the Item Object itself.

Example: Lets take this Collection: new ObservableCollection<string>(){ "String1", "String2", String3"} If the SelectedItem is/should be String1 the SelectedIndex is 0.

So just replace

<Setter Property="SelectedIndex" Value="{Binding CurrentPlanSet, Mode=TwoWay}"/>

with

<Setter Property="SelectedItem" Value="{Binding CurrentPlanSet, Mode=TwoWay}"/>

Upvotes: 1

Related Questions