views:

25

answers:

1

Hi,

I have the DataTable with following columns:

id, Name, Description, ParentId

and would like to create a WPF control (.NET 4.0 framework) which implements a combobox which displays the names which are bound to values of id. So when the user selects a name displayed in the combobox the behind logic has to retrieve its id value.

I would be very thankful if anyone could show the way of doing the described above.

+1  A: 

Like so:

In your XAML file, put:

 <ComboBox x:Name="NameComboBox" DisplayMemberPath="Name" SelectedValuePath="id"/>

In your code behind, put:

NameComboBox.ItemSource = myTable;

(myTable being a reference to the table you mentioned).

then you can reach the id of the currently selected person in the combo box using the expression:

NameComboBox.SelectedValue
Omer Raviv