Reputation:
I am using the code I found here to print my datagrids. The only problem is the DataTable I use as the ItemsSource for my DataGrid has more columns than I am displaying in the datagrid, which are being added to the print out too.
How can I only add the values that are visible to the flowdocument?
for (int j = 0; j < row.Row.ItemArray.Length; j++)
{
r.Cells.Add(new TableCell(new Paragraph(new Run(row.Row.ItemArray[j].ToString()))));
r.Cells.Last().ColumnSpan = 4;
r.Cells.Last().Padding = new Thickness(4);
r.Cells.Last().BorderBrush = Brushes.DarkGray;
r.Cells.Last().BorderThickness = new Thickness(0, 0, 1, 1);
}
Upvotes: 0
Views: 174
Reputation: 96
When picking the columns from the data grid, filter them by visibility
var headerList = dataGrid.Columns.Where(x=>x.Visibility == Visibility.Visible).Select(e => e.Header.ToString()).ToList();
Upvotes: 1