Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to export GridView to CSV?

$
0
0

I have following sample code -

    <ListViewItemsSource="{Binding Path=Employees}">

                           
<ListView.ItemContainerStyle>
                               
<StyleTargetType="{x:Type ListViewItem}">
                                   
<SetterProperty="Focusable"Value="False"/>
                               
</Style>
                           
</ListView.ItemContainerStyle>
                           
<ListView.Resources>
                               
<StyleTargetType="{x:Type CheckBox}" x:Key="DataGridCheckBox">
                                   
<SetterProperty="HorizontalAlignment"Value="Center"/>
                                   
<SetterProperty="HorizontalContentAlignment"Value="Center"/>
                                   
<SetterProperty="IsEnabled"Value="True"/>
                                   
<SetterProperty="Margin"Value="4"/>
                                   
<SetterProperty="VerticalAlignment"Value="Center"/>
                                   
<SetterProperty="VerticalContentAlignment"Value="Center"/>
                                   
<SetterProperty="Width"Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type GridViewColumn}},Path=ActualWidth}"/>
                               
</Style>
                           
</ListView.Resources>

                           
<ListView.View>
                               
<GridView x:Name="EmployeesGridView">
                                   
<GridViewColumnHeader="IsEligible">
                                       
<GridViewColumn.CellTemplate>
                                           
<DataTemplate>
                                               
<CheckBoxStyle="{StaticResource DataGridCheckBox}"IsChecked="{Binding Path=IsSelected}"/>
                                           
</DataTemplate>
                                       
</GridViewColumn.CellTemplate>
                                   
</GridViewColumn>

                                   
<GridViewColumnHeader="Name">
                                       
<GridViewColumn.CellTemplate>
                                           
<DataTemplate>
                                               
<TextBlock>
                                           
<TextBlock>
                                               
<TextBlockText="{Binding Path=Employee.Name}"/>
                                           
</TextBlock>
                                       
</TextBlock>
                               
</DataTemplate>
                                       
</GridViewColumn.CellTemplate>
                                   
</GridViewColumn>

                                   
<GridViewColumnHeader="Age">
                                       
<GridViewColumn.CellTemplate>
                                           
<DataTemplate>
                                               
<TextBlockText="{Binding Age}"/>
                                           
</DataTemplate>
                                       
</GridViewColumn.CellTemplate>
                                   
</GridViewColumn>
                               
</GridView>
                           
</ListView.View>
                       
</ListView>

How can I export this data to CSV?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>