This is a migrated thread and some comments may be shown as answers.

exporting hieararchical gridview

2 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
AAA
Top achievements
Rank 1
AAA asked on 02 Aug 2016, 06:50 AM

 How to not Export specified columns for each parent row child rows when exporting to excel in telerik radgridview ui winf

 

I a have hierarchical telerik radgridview in winform. in this radgridview master template i have a rows that each row has child rows that are null in some columns for all child rows of that parent row and not for others.

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 radgridview 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.

tnx

2 Answers, 1 is accepted

Sort by
0
AAA
Top achievements
Rank 1
answered on 02 Aug 2016, 09:06 AM

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

 

0
Dimitar
Telerik team
answered on 02 Aug 2016, 09:26 AM
Hello,

Thank you for writing. 

I am glad that you have found a solution for this. Nevertheless, the other possible way is to manually export the grid. We have an example for this in our demo application (see attached image). 

Detailed information about the Spread Processing library is available here: Overview.

I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
AAA
Top achievements
Rank 1
Answers by
AAA
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or