HOW I CAN BIND DATATABLE TO LISTBOX IN WPF?

Total Post:24

Points:168
WPF 
WPF
 2915  View(s)
Ratings:
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

  1. Post:105

    Points:735
    Re: How I can bind datatable to LISTBOX in wpf?

    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>

      Modified On Mar-30-2018 05:17:07 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!