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

Total Post:24

Points:168
Posted on    July-18-2013 2:11 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 1879  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

Points:735
Posted on    July-18-2013 2:45 AM

Solution!

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"/>

    </ComboBox>

    <ListBox ItemsSource="{Binding}"

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

</DockPanel>


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

Follow MindStick