0

这是绑定到 table 的列表视图:

   <ListView x:Name="lvwRpt" HorizontalAlignment="Left" ItemsSource="{Binding Path=BankWithdraw}" Height="335" Margin="23,230,0,0" VerticalAlignment="Top" Width="949" SelectionChanged="lvwRpt_SelectionChanged">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="0"  Header="id" DisplayMemberBinding="{Binding Path=WithdrawID}" />
                    <GridViewColumn Width="85"  Header="Date" DisplayMemberBinding="{Binding Path=Dated}" />
                    <GridViewColumn Width="85"  Header="Acc Code" DisplayMemberBinding="{Binding Path=Account}" />
                    <GridViewColumn Width="120" Header="Bank Title" DisplayMemberBinding="{Binding Path=Account}" />
                    <GridViewColumn Width="120" Header="Description" DisplayMemberBinding="{Binding Path=Checknum}" />
                    <GridViewColumn Width="120" Header="Cheque Num" DisplayMemberBinding="{Binding Path=Checknum}" />
                    <GridViewColumn Width="115" Header="Ch. Date" DisplayMemberBinding="{Binding Path=CheckDate}" />
                    <GridViewColumn Width="120" Header="Amount" DisplayMemberBinding="{Binding Path=Amount}" />
                </GridView>
            </ListView.View>
        </ListView>

但是我在WPF表单上有3个复选框。当检查一个新的复选框时,我希望从此列表视图中的数据库加载中相应的新表格。表示列表视图的标题是每个表的标题名称相同,但绑定“ {绑定路径= _ _}”是不同的。如何做到这一点?

4

1 回答 1

1

尝试删除 ItemsSource="{Binding Path=BankWithdraw}"。ListView 看起来像

<ListView x:Name="lvwRpt" HorizontalAlignment="Left" Height="335" Margin="23,230,0,0" VerticalAlignment="Top" Width="949" SelectionChanged="lvwRpt_SelectionChanged">
        <ListView.View>
           <!--content-->
        </ListView.View>
</ListView>

在后面的代码中尝试使用:

private void CheckBox1_CheckedChanged(Object sender, EventArgs e)
{
   this.lvwRpt.DataSource = collection1;
}

private void CheckBox2_CheckedChanged(Object sender, EventArgs e)
{
   this.lvwRpt.DataSource = collection2;
}

如果您使用 MVVM,请在 VM 中将 BankWithdraw 属性作为 IEnumerable 引入,并在您单击复选框时更改它

于 2013-10-30T07:52:18.350 回答