stacks
stacks

Reputation: 231

Setting WPFToolkit AutoCompleteBox

I have a DataTable named names in which i have 3 columns idnr,name,surname and i wish to add all rows from column surname to WPFToolkit's AutoCompleteBox as ItemsSource.

<toolkit:AutoCompleteBox x:Name="boxbox" Height="23"
  ItemsSource="{Binding surname}"
SelectedItem="{Binding surname, Mode=TwoWay}" Margin="93,38,119,95" />

Upvotes: 1

Views: 234

Answers (1)

mm8
mm8

Reputation: 169160

Set (boxbox.ItemsSource = dataTable.DefaultView;) or bind the ItemsSource property to the DefaultView of the DataTable and define an ItemTemplate to display the value of the surname column. Also set the ValueMemberPath property:

<toolkit:AutoCompleteBox x:Name="boxbox" Height="23" 
                        ItemsSource="{Binding dt.DefaultView}"
                        ValueMemberPath="surname"
                        Margin="93,38,119,95">
    <toolkit:AutoCompleteBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding surname}" />
        </DataTemplate>
    </toolkit:AutoCompleteBox.ItemTemplate>
</toolkit:AutoCompleteBox>

If you bind to the ItemsSource, the source property should return the DefaultView property of the DataTable. You also need to make sure that you set the DataContext of the AutoCompleteBox to an instance of the class where the source property is defined.

Upvotes: 1

Related Questions