0
votes

I have a datatable as

  DataTable dt = new DataTable( "Table1" );
  dt.Columns.Add( "c1" );
  dt.Columns.Add( "c2" );
  dt.Columns.Add( "c3" );
  DataRow dr = dt.NewRow();
  dr["c1"] = "100";
  dr["c2"] = "100";
  dr["c3"] = "100";
  dt.Rows.Add( dr );
  dt.AcceptChanges();
  printListView.DataContext = dt;

I have also a listview for showing the table.

ListView                                    
                  HorizontalAlignment="Stretch" 
                  HorizontalContentAlignment="Stretch" 
                  SelectionMode="Single" 
                  ItemsSource="{Binding}" 
                  Name="printListView" 
                  Margin="10"
                  ListView.View
                        GridView
                              GridViewColumn Header="c1" DisplayMemberBinding="{Binding c1}"/
                              GridViewColumn Header="c2" DisplayMemberBinding="{Binding c2}"/
                              GridViewColumn Header="c3" DisplayMemberBinding="{Binding c3}"/
                        /GridView
                  /ListView.View
            /ListView

How can I print this table?

Thanks

2

2 Answers

0
votes

Here's a one-liner that will dump the data to an XML file on disk:

dt.WriteXml(@"c:\temp\MyDataTable.xml");

(In this example, you may need to create the temp folder manually.) Once the file is created, you can open it in your favorite browser or XML viewer and view it or print it.