在 WPF 数据网格中打印可见行



我正在使用我在这里找到的代码来打印我的数据网格。唯一的问题是我用作数据网格的 ItemsSource 的数据表的列数比我在数据网格中显示的列多,这些列也被添加到打印输出中。

如何仅添加对流文档可见的值?

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);
}

从数据网格中选取列时,请按可见性筛选它们

var headerList = dataGrid.Columns.Where(x=>x.Visibility == Visibility.Visible).Select(e => e.Header.ToString()).ToList();

最新更新