【问题标题】:hide specified columns for each parent row child rows when exporting to excel in telerik radgridview ui winform在telerik radgridview ui winform中导出到excel时隐藏每个父行子行的指定列
【发布时间】:2016-12-07 09:11:36
【问题描述】:

我的winform 应用程序中有一个分层的telerik gridview。 在这个gridview 主模板中,我有行,每个行都有子行,并且在该父行的所有子行的某些列中为空。

我写了一个代码,只让一个父行展开,当展开该父行时,只显示至少在一个子行中具有值的列,并隐藏其子行对于该父行全部为空的列radGridView1_ChildViewExpanded 事件处理程序。

我的问题是当我想将此分层telerik gridview 导出到 excel 文件时。在导出时我应该怎么做才能达到我所描述的,这意味着只导出在其子行中至少有一个值的列,而不是为每个父行导出其他值。

【问题讨论】:

    标签: c# winforms telerik export-to-excel radgridview


    【解决方案1】:

    为此,您可以使用 GridViewSpreadExportHiddenRowOption 属性并将其设置为 DoNotExport。然后,要定义隐藏哪些行,请将它们的 IsVisible 属性设置为 false

    radGridView1.Rows[0].IsVisible = false;
    

    您可以在 Telerik UI for WinForms 文档的以下文章中找到有关此问题的更多信息:Export to Excel

    【讨论】:

      【解决方案2】:

      我使用了这段代码,它成功了

      void spreadExporter_CellFormatting(object sender, Telerik.WinControls.Export.CellFormattingEventArgs e)
          {
              if (e.GridRowInfoType == typeof(GridViewHierarchyRowInfo))
              {
                  int i = 0;
                  foreach (GridViewColumn column in radGridView1.MasterTemplate.Templates[0].Columns)
                  {
                      if (i > 1)
                      {
                          int TotalNullRecords = (from row in e.GridCellInfo.RowInfo.ChildRows
                                                  where string.IsNullOrWhiteSpace(row.Cells[column.Name].Value.ToString())
                                                  select row).ToList().Count;
      
                          if (TotalNullRecords == e.GridCellInfo.RowInfo.ChildRows.Count)
                          {
                              radGridView1.MasterTemplate.Templates[0].Columns[column.Name].IsVisible = false;
                          }
                          else
                              radGridView1.MasterTemplate.Templates[0].Columns[column.Name].IsVisible = true;
                      }
                      i++;
                  }
              }
          }
      

      【讨论】:

      • 我不会那样做。此事件经常被触发并且有其他目的 - 格式化单元格外观。因此,这将对您的应用产生性能影响。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-04
      • 2016-11-25
      • 1970-01-01
      • 2012-03-12
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多