1

I have been looking all over the internet (googling pretty much) and have found no answer to this simple question and thus I'm starting to think it might not be possible.

Ok so I have a RibbonCombobox up in my ribbon. Here's the code

<ribbon:RibbonComboBox  
                  SelectionBoxWidth="150"
                  VerticalAlignment="Center" 
                  IsEditable="False" Name="cbConsultationRapideEmploye">
                        <ribbon:RibbonGallery Name="cbConsultationRapideEmployeG" SelectedValuePath="Name"
                          MaxColumnCount="1">
                            <ribbon:RibbonGalleryCategory Name="cbConsultationRapideEmployeGC" Margin="0" Padding="0" ItemsSource="{Binding}" DisplayMemberPath="NomEmploye" />
                        </ribbon:RibbonGallery>
                    </ribbon:RibbonComboBox>

I populate this combobox from a dataset on load.

What I want to do is set on load the selected item to be the first one in the list. I know that there is a SelectedItem property on the RibbonGallery, but sometimes it works just way better with an index.

I could probably roll with setting the SelectedItem as the first item in my Dataset but in the case of fetching info, fetching the text is not really an option as I will want the ID (from the database) of the employee and not his name.

If someone has an alternate solution I'm all open to suggestions.

EDIT: As per request here is the code where the combobox gets his values.

bd.openConnection()
dsCbNomEmploye = bd.queryds("SELECT Prenom + ' ' + Nom AS NomEmploye FROM tblEmploye ORDER BY 1", "tblEmploye")
cbConsultationRapideEmploye.DataContext = dsCbNomEmploye.Tables(0).DefaultView
4

2 回答 2

1

I ended up adding the SelectedValuePath on the RibbonGallery tag like so

<ribbon:RibbonComboBox  
                  SelectionBoxWidth="150"
                  VerticalAlignment="Center" 
                  IsEditable="False" Name="cbConsultationRapideEmploye">
                        <ribbon:RibbonGallery SelectedValuePath="idEmploye" Name="cbConsultationRapideEmployeG"
                          MaxColumnCount="1">
                            <ribbon:RibbonGalleryCategory Name="cbConsultationRapideEmployeGC" Margin="0" Padding="0" ItemsSource="{Binding}" DisplayMemberPath="NomEmploye" />
                        </ribbon:RibbonGallery>
                    </ribbon:RibbonComboBox>

Afterwards if you need the text value you can get it with the cbConsultationRapideEmployeG.SelectedItem and if you need the actual value you can get it with cbConsultationRapideEmployeG.SelectedValue

In short SelectedItem=Displayed value SelectedValue=not shown value

于 2012-09-29T15:30:24.827 回答
0

I did this in WPF Combobox (XAML) and worked. May be it will give you an idea

ItemsSoruce={Binding} SelectedIndex={Binding ElementName=yourcomboboxname, Path=SelectedItem} IsSynchronizedWithCurrentItem = True
于 2012-09-27T01:46:56.760 回答