title: Get content of GridView
body: <p>I have an application C#/WPF with a ListView containing a GridView. I want to get the content to create a CSV file with all values.</p>
  
  <p>I have made some research to do that but I only found solution for windows form or WPF DataGrid. Nothing for GridView.</p>
  
  <p>My List:</p>
  
  <pre><code>&lt;ListView Grid.Row="1" x:Name="myListView" 
            BorderBrush="White" HorizontalAlignment="Stretch"
            ItemsSource="{Binding Path=myItem}" SelectedItem="{Binding Path=ActualItem}"&gt;
      &lt;ListView.View&gt;
          &lt;GridView x:Name="myGridView"&gt;  
  
              &lt;GridViewColumn Header="{x:Static p:Resources.NAME}"
                              DisplayMemberBinding="{Binding Path=Name,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
                              Width="{StaticResource doubleNaN}"/&gt;
  
              &lt;GridViewColumn Header="{x:Static p:Resources.LABEL}"
                              DisplayMemberBinding="{Binding Path=Label,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/&gt;
  
          &lt;/GridView&gt;
      &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>I can get the header but no the content:</p>
  
  <pre><code>System.Text.StringBuilder csv = new System.Text.StringBuilder();                        
  String separator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
  
  foreach (System.Windows.Controls.GridViewColumn col in myGridView.Columns)
  {
      string header = col.Header as String;
      if (!String.IsNullOrWhiteSpace(header))
      {
          csv.Append(header + separator);
      }
  }
  csv.AppendLine();
  
  System.IO.File.WriteAllText(path, csv.ToString());
  </code></pre>
  
  <p>How can I get the content to make my CSV file ?</p>