1

I have a hierarchical telerik gridview in my winform app. In this gridview master template I have rows that each one has child rows and are null in some columns for all child rows of that parent row.

I wrote a code that only let one parent row to be expanded and when expanding that parent row show only the columns that has value at least in one child row and hide columns that its child rows are all null for that parent row with radGridView1_ChildViewExpanded event handler.

My problem is when i want to export this hierarchical telerik gridview to excel file. what should i do in exporting to achieve to what i described, means exports only the columns that have at least one value in its child rows and not export others for each parent row.

AAAE_N
  • 305
  • 4
  • 17

2 Answers2

1

To do that, you can use the HiddenRowOption property of GridViewSpreadExport and set it to DoNotExport. Then, to define which rows are hidden, set their IsVisible property to false

radGridView1.Rows[0].IsVisible = false;

More information on the matter you can find in the following article from the Telerik UI for WinForms documentation: Export to Excel

checho
  • 3,092
  • 3
  • 18
  • 30
1

I used this code and it worked

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++;
            }
        }
    }
AAAE_N
  • 305
  • 4
  • 17
  • I would not do that. This event is triggered quite often and has other purpose - to format cell appearance. So this will introduce performance impact on your app. – checho Aug 02 '16 at 10:31