getc he
getc he

Reputation: 107

Binding LIST VIEW in Wpf with multiple tables using C#

Here is my list view that is bound to 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>

but i have 3 check boxes on wpf form .Whenever a new check box is checked i want corresponding new table from data base load in this list view .Situation is headers names of list view are the same for each table but binding " {Binding Path= __}" are different .How this can be done ?

Upvotes: 0

Views: 940

Answers (1)

Alekstim
Alekstim

Reputation: 462

Try to remove ItemsSource="{Binding Path=BankWithdraw}". ListView will look like

<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>

In code behhind try to use:

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

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

If you're using MVVM introduce BankWithdraw property as IEnumerable in VM and change it when you're clicking on checkbox

Upvotes: 1

Related Questions