【问题标题】:Print visible rows in WPF DataGrid在 WPF DataGrid 中打印可见行
【发布时间】:2020-01-23 11:27:33
【问题描述】:

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

我怎样才能只添加对流文档可见的值?

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

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:

    从数据网格中选择列时,按可见性过滤它们

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

    【讨论】:

      猜你喜欢
      • 2010-10-14
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多