Add a data source to your WPF Application. For this, follow the steps below.
-
Open the Project menu and click the Add New Data Source item.

-
Choose a Database as a type of data source.

-
Then choose a Dataset as a Database Model.

-
As a data source, choose the Microsoft Access Database File. As a data connection, choose the nwind database. By default, it is stored in the following path.C:\Users\Public\Documents\DevExpress Demos 18.2\Components\Data

-
In the Tables menu, choose Categories.

- After this, click Finish to close the wizard.
-
Bind the ComboBoxEdit to the data source. Add the following code:
C# |
using System.Windows;
namespace Combobox_binding_to_data
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ComboBoxEdit1.ItemsSource =
new nwindDataSetTableAdapters.CategoriesTableAdapter().GetData();
}
}
}
|
Set the DisplayMember property to "CategoryName". Set the EditValue property to "CategoryID", and the ValueMember property to "CategoryID":
XAML |
<Window x:Class="Combobox_binding_to_data.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
Title="MainWindow" Height="300" Width="300">
<Grid>
<dxe:ComboBoxEdit ValueMember="CategoryID" DisplayMember="CategoryName"
EditValue="{Binding CategoryID}" HorizontalAlignment="Center"
VerticalAlignment="Top" Height="30" Width="250" Name="ComboBoxEdit1">
</dxe:ComboBoxEdit>
</Grid>
</Window>
|
-
Run the application to see the result.

You can change the style of the ComboBoxEdit by setting its StyleSettings property to 'CheckedComboBoxStyleSettings' or 'RadioComboBoxStyleSettings'.

XAML |
<Window x:Class="Combobox_binding_to_data.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
Title="MainWindow" Height="300" Width="300">
<Grid>
<dxe:ComboBoxEdit ValueMember="CategoryID" DisplayMember="CategoryName"
EditValue="{Binding CategoryID}" HorizontalAlignment="Center" VerticalAlignment="Top"
Height="30" Width="250" Name="ComboBoxEdit1">
<dxe:ComboBoxEdit.StyleSettings>
<dxe:CheckedComboBoxStyleSettings />
</dxe:ComboBoxEdit.StyleSettings>
</dxe:ComboBoxEdit>
</Grid>
</Window>
|

XAML |
<Window x:Class="Combobox_binding_to_data.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
Title="MainWindow" Height="300" Width="300">
<Grid>
<dxe:ComboBoxEdit ValueMember="CategoryID" DisplayMember="CategoryName"
EditValue="{Binding CategoryID}" HorizontalAlignment="Center" VerticalAlignment="Top"
Height="30" Width="250" Name="ComboBoxEdit1">
<dxe:ComboBoxEdit.StyleSettings>
<dxe:RadioComboBoxStyleSettings />
</dxe:ComboBoxEdit.StyleSettings>
</dxe:ComboBoxEdit>
</Grid>
</Window>
|