HOW I CAN BIND DATATABLE TO LISTBOX IN WPF?

Kate Smith

Total Post:24

Points:168
Posted by  Kate Smith
WPF 
WPF
 2523  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. shreesh chandra shukla

    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>

Answer

NEWSLETTER

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