Home > DeveloperSection > Forums > How I can bind datatable to LISTBOX in wpf?
Kate Smith
Kate Smith

Total Post:24

Posted on    July-18-2013 2:11 AM


 1 Reply(s)
 2407  View(s)
Rate this:
Hi Experts!

How can I bind datatable to a ListBox and select a field which I want to display in the ListBox in WPF.

Thank  in addvance

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    July-18-2013 2:45 AM


Here is a pure XAML solution :

<DockPanel DataContext="{StaticResource myDataViewSource}">

    <ComboBox DockPanel.Dock="Bottom" x:Name="FieldSelector" SelectedIndex="0">

        <ComboBoxItem Content="Field1" Tag="Field1"/>

        <ComboBoxItem Content="Field2" Tag="Field2"/>

        <ComboBoxItem Content="Field3" Tag="Field3"/>

        <ComboBoxItem Content="Field4" Tag="Field4"/>


    <ListBox ItemsSource="{Binding}"

             DisplayMemberPath="{Binding ElementName=FieldSelector,Path=SelectedItem.Tag}" />


Don't want to miss updates? Please click the below button!

Follow MindStick