2011-11-11 5 views
0

私は、プリンタで印刷したいデータテーブルを持つフロードキュメントを作成しようとしています。私は、フロードキュメントとプリンタのものを作成することができますが、私はテーブルを作成する方法がわかりません。FlowTocumentのDataTable

私は、誰かが私を助けることができると思います。ここでD

が私のコードです:

 //Creating flow document 
     Paragraph myParagraph = new Paragraph(); 

     //Add content to the paragraph 
     myParagraph.Inlines.Add(new Bold(new Run("List of tasks (" + TasksToShow.Count + ")"))); 

     //Create content of paragraph 
     DataTable myTable = new DataTable(); 
     myTable.Columns.Add("Task ID", typeof(int)); 
     myTable.Columns.Add("Task name", typeof(string)); 

     foreach (Task task in TasksToShow) 
     { 
      myTable.Rows.Add(task.TaskID, task.TaskName); 
     } 

     //Adding content to the flow document 
     FlowDocument myFlowDocument = new FlowDocument(); 
     myFlowDocument.Blocks.Add(myParagraph); 
     myFlowDocument.Blocks.Add(myTable);    //This line fails :(

     //Print the document 
     PrintDialog dialog = new PrintDialog(); 
     if(dialog.ShowDialog() == true) 
     { 
      int margin = 5; 
      Size pageSize = new Size(dialog.PrintableAreaWidth - margin * 2, dialog.PrintableAreaHeight - margin * 2); 
      IDocumentPaginatorSource paginator = myFlowDocument; 
      paginator.DocumentPaginator.PageSize = pageSize; 
      dialog.PrintDocument(paginator.DocumentPaginator, "Flow print"); 
     } 

答えて

1

あなたは

// Create the parent FlowDocument... 
flowDoc = new FlowDocument(); 

// Create the Table... 
table1 = new Table(); 
// ...and add it to the FlowDocument Blocks collection. 
flowDoc.Blocks.Add(table1); 


// Set some global formatting properties for the table. 
table1.CellSpacing = 10; 
table1.Background = Brushes.White; 

plsはこのlinksを通過.....次のように行うことができますより多くの場合info

この後、このデンドを変更することができますURの要件...

+0

実際に私を助けたのはあなたのリンクでした:D – Sulby