Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add option "All" to a combobox in WPF with binding from Database

I have the following ComboBox in WPF. I know that I can add option ALL with CompositeCollection, but I don't know how. It would be great if somebody help me out with a short tutorial.

<ComboBox SelectionChanged="ComboBoxOperatingPoints_SelectionChanged" 
          x:Name="ComboBoxOperatingPoints" 
          DropDownOpened="ComboBoxOperatingPoints_DropDownOpened_1"
          FontSize="30" 
          HorizontalAlignment="Right" 
          Margin="40,40,0,0" 
          VerticalAlignment="Top" 
          Width="200" 
          Height="50"
          IsSynchronizedWithCurrentItem="True"
          ItemsSource="{Binding OperatingPoints}"
          DisplayMemberPath="name"
          SelectedValue="{Binding OperatingPointID,UpdateSourceTrigger=PropertyChanged,TargetNullValue=''}"
          SelectedValuePath="operating_point_id">
</ComboBox>
like image 566
Lóri Nóda Avatar asked Sep 07 '13 09:09

Lóri Nóda


People also ask

How to add combo box to access form?

The combo box can also be a stand-alone combo box on the Access form. In this How To, I will show to add the <All> or <N/A> option on the list of combo box. The selection option: <All> or <N/A> is not listed on the table, but we can add on top of the list in the combo box. I have created a from below and added the combo box for selecting the state.

How to add <all> option on combo box in Salesforce?

We want to add <All> option on this combo box. Under the Data tab of the property sheet of the combo box, you will see the Row Source in the picture below: Row Source = SELECT [Customers]. [ID], [Customers]. [State] FROM Customers ORDER BY [State]; Actually, there are two fields/columns in the combo box.

Can MGT query the combo box after update event?

In the after update event for the combo box have you tried to requery the combo box. I think you misunderstood me. I've got a combobox linked to a static table. Mostly people will be querying using specific options from the combobox (status codes). But mgt need to be able to query it seeing all status's.

How to bind enum to combobox in Java?

Binding Enum to Combobox – We can bind an enum to the combobox by creating an ObjectDataProvider in the resource and binding it to the combobox as shown in the snippet below. I have created an enum Gender and binded it to combobox. 4. Binding to SelectedValue and SelectedValuePath –


1 Answers

Try this (msdn):

<ComboBox x:Name="ComboBoxOperatingPoints"  
          SelectionChanged="ComboBoxOperatingPoints_SelectionChanged" 
          Width="200" Height="50"
          IsSynchronizedWithCurrentItem="True"
          DisplayMemberPath="name"        
          SelectedValuePath="operating_point_id">
    <ComboBox.Resources>
        <CollectionViewSource x:Key="comboBoxSource" Source="{Binding Path=OperatingPoints}" />
    </ComboBox.Resources>
    <ComboBox.ItemsSource>
        <CompositeCollection>
            <local:OpPoint name="all" operating_point_id="-1" />
            <CollectionContainer Collection="{Binding Source={StaticResource comboBoxSource}}" />
        </CompositeCollection>
    </ComboBox.ItemsSource>
</ComboBox>
like image 173
kmatyaszek Avatar answered Sep 29 '22 05:09

kmatyaszek