user6439507
user6439507

Reputation:

Print visible rows in WPF DataGrid

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

Answers (1)

DG.
DG.

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

Related Questions