exporting hieararchical gridview

3 posts, 0 answers
  1. AAA
    AAA avatar
    2 posts
    Member since:
    Aug 2016

    Posted 02 Aug Link to this post

     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. AAA
    AAA avatar
    2 posts
    Member since:
    Aug 2016

    Posted 02 Aug Link to this post

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

     

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 02 Aug Link to this post

    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.
Back to Top