简体   繁体   中英

listbox doesn't show displaymember

I have a ListBox , and it has a Binding to dtAtt , but when I run the app, the ListBox show the items with empty content.

Code:

Xaml:

<Expander Name="expandAtt" Header="Attachment">
    <ListBox x:Name="lstAtt" MouseDoubleClick="lstAtt_MouseDoubleClick" ItemsSource="{Binding}" DisplayMemberPath="Name">
    </ListBox>
</Expander>

C#:

    public DataTable  dtAtt;

    string sql = "SELECT Name FROM Item2Inv_Link";
    dtAtt = DataBase.GetTable(sql);
    lstAtt.ItemsSource = dtAtt.Select("Att_Pkg=0");

You need to change your your source you're binding in the code just a bit. Try this:

lstAtt.ItemsSource = dtAtt.Select("Att_Pkg=0").CopyToDataTable().DefaultView;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM