2013-10-30 71 views
0

這裏多個表是綁定到表我的列表視圖:綁定列表視圖使用C#

<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個複選框被選中,我想對應的新表從數據庫加載的列表視圖中查看。對於每個表而言,列表視圖的標題名稱都是相同的,但綁定「{綁定路徑= _ _}」是不同的。如何實現?

+0

如果我正確理解你的問題,你需要改變ItemSource(BankWithdraw)你的ListView每個複選框點擊事件 – Alekstim

+0

確切地說,看我編輯的問題 –

回答

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> 

在代碼behhind嘗試使用:

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介紹BankWithdraw財產爲IEnumerable在VM和改變它,當你點擊複選框

+0

不,我沒有使用任何框架......我如何分配表名稱和它列列表視圖。它對我們有效...... this.lvwRpt.ItemSource = BankWithdraw; 。如何將列分配給listview? –

+0

你說過,對於從數據庫加載的每個數據,標題都是相同的。對於從數據庫加載的每個數據,DisplayMemberBinding屬性是否相同,是否正確? – Alekstim

+0

對於所有表格,Header =「id」是相同的,但DisplayMemberBinding =「{Binding Path = WithdrawID}」路徑對於從數據庫加載的每個表格都是不同的。.....對於其餘列,這是相同的。 –