0

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

1

2 Answers 2

2

One way would be to bind the table to a listview and then make a document out of it and print it.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.