0

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 ?

2
  • If I understood your question correctly, you need to to change ItemSource (BankWithdraw) for your ListView on every checkboxes clicking event Commented Oct 30, 2013 at 7:28
  • exactly , see my edited question Commented Oct 30, 2013 at 7:31

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

No i am not using any framework ... How i can assign table name and it column to list view .Is it valid to us this ......this.lvwRpt.ItemSource = BankWithdraw; .How to assign column to listview ?
You said that headers were same for each data which was loaded from database. Is it correct that DisplayMemberBinding property is the same for each data which is loaded from database?
Header="id" is same for all tables but DisplayMemberBinding="{Binding Path=WithdrawID}" path is different for each table loaded from database.....This is same for remaining columns.
Ok. I finally understand you. I think it will help you tech.pro/tutorial/807/…
Why? You should write dataTemplate for each source from database and dataTemplateSelector. But also you can set GridViewColumn data in code-behind using Binding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.