简体   繁体   English

列表框不显示displaymember

[英]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. 我有一个ListBox ,并且它具有dtAttBinding ,但是当我运行该应用程序时,ListBox会显示内容为空的项目。

Code: 码:

Xaml: XAML:

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

C#: 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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