Omar Harras

Omar Harras

  • NA
  • 2
  • 4.9k

Get the Value of WPF Listview rows

Apr 29 2016 6:12 AM

Get the Value of WPF Listview rows and compare them with database field using Linq query

i want to compare ECH_INTITULE in my database with the values of the listview rows but my problem is that i can't access the Listview items in my Linq query

here is my Xaml code for my Listview :

  1. <ListView x:Name="listView" SelectedItem="{Binding SelectedItem}" ItemsSource="{Binding}" DataContext="query" HorizontalAlignment="Left" Height="430" Margin="24,47,0,0" VerticalAlignment="Top" Width="940" >  
  2.             <ListView.View>  
  3.                 <GridView x:Name="gridView">  
  4.                     <GridViewColumn Header="Fournisseur" DisplayMemberBinding="{Binding fournisseur}" Width="280"/>  
  5.                     <GridViewColumn Header ="Adresse Mail" DisplayMemberBinding="{Binding email}" Width="270"/>  
  6.                     <GridViewColumn Header ="Date" DisplayMemberBinding="{Binding date}" Width="150"/>  
  7.                     <GridViewColumn Header="Fichier CSV" DisplayMemberBinding="{Binding xxx}" Width="105"/>  
  8.                     <GridViewColumn Header="Fichier PDF" DisplayMemberBinding="{Binding xxx}" Width="105"/>  
  9.                 </GridView>  
  10.             </ListView.View>  
  11.         </ListView>  
and here is my c# code :
 
  1. //Generate CSV Files for each item in the Listview  
  2.             CsvFileDescription outpCsvFileDescription = new CsvFileDescription  
  3.             {  
  4.                 SeparatorChar = ',',  
  5.                 FirstLineHasColumnNames = true  
  6.             };  
  7.   
  8.             for (int i = 0; i < listView.Items.Count; i++)  
  9.             {  
  10.                 var infoEcheances = from f in db.F_ECHEANCES  
  11.                                     //where f.ECH_Intitule == ???  
  12.                                     select new { f.ECH_Intitule, f.ECH_DateEch, f.CG_Num, f.ECH_Piece, f.ECH_RefPiece, f.ECH_Montant, f.ECH_Libelle };  
  13.   
  14.   
  15.                 CsvContext cc = new CsvContext();  
  16.                 string myPath = @"C:\Users\DefaultAccount\Desktop\Projet Top Of Travel\FichiersCSV\";  
  17.                 string filename = string.Format("Facture{0}.csv", i);  
  18.                 string finalPath = System.IO.Path.Combine(myPath, filename);  
  19.                 cc.Write(infoEcheances, finalPath, outpCsvFileDescription);  
  20.             }  
 
 
 
 

Answers (1)