Completed
Last Updated: 20 Nov 2018 11:03 by Dimitar
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 14 Nov 2018 08:29
Category: GridView
Type: Bug Report
1
FIX. RadGridView - broken layout of the ColumnGroupsViewDefinition when exporting with GridViewSpreadExport and some columns are hidden
To reproduce: use the following code snippet:

    Sub New()

        InitializeComponent()

        Dim view As New ColumnGroupsViewDefinition()
        view.ColumnGroups.Add(New GridViewColumnGroup("Customer Contact"))
        view.ColumnGroups.Add(New GridViewColumnGroup("Details"))
        view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Address"))
        view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Contact"))
        view.ColumnGroups(0).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(0).Rows(0).ColumnNames.Add("CompanyName")
        view.ColumnGroups(0).Rows(0).ColumnNames.Add("ContactName")
        view.ColumnGroups(0).Rows(0).ColumnNames.Add("ContactTitle")
        view.ColumnGroups(1).Groups(0).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(1).Groups(0).Rows(0).ColumnNames.Add("Address")
        view.ColumnGroups(1).Groups(0).Rows(0).ColumnNames.Add("City")
        view.ColumnGroups(1).Groups(0).Rows(0).ColumnNames.Add("Country")
        view.ColumnGroups(1).Groups(1).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(1).Groups(1).Rows(0).ColumnNames.Add("Phone")
        view.ColumnGroups(1).Groups(1).Rows(0).ColumnNames.Add("Fax")
        RadGridView1.ViewDefinition = view 


    End Sub

    Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.CustomersTableAdapter.Fill(Me.NwindDataSet.Customers)
        Me.RadGridView1.BestFitColumns(BestFitColumnMode.AllCells)

        RadGridView1.Columns("Fax").IsVisible = False
        RadGridView1.Columns("Phone").IsVisible = False
        
        Dim spreadExporter As GridViewSpreadExport = New GridViewSpreadExport(Me.RadGridView1)
        Dim exportRenderer As New SpreadExportRenderer()
        spreadExporter.HiddenColumnOption = Export.HiddenOption.ExportAsHidden
        spreadExporter.FreezeHeaderRow = True
        spreadExporter.ExportGroupedColumns = True
        spreadExporter.ExportChildRowsGrouped = True
        spreadExporter.ExportVisualSettings = True
        spreadExporter.ExportHierarchy = True
        spreadExporter.ExportViewDefinition = True
        spreadExporter.ExportFormat = SpreadExportFormat.Xlsx
        Dim fileName = "..\..\export" & DateTime.Now.ToLongTimeString().Replace(":", "_") & ".xlsx"
        
        spreadExporter.RunExport(fileName, exportRenderer)
        Process.Start(fileName)
    End Sub

Workaround: instead of hiding all the columns inside a group, hide the entire group: 

    Sub New()

        InitializeComponent()

        Dim view As New ColumnGroupsViewDefinition()
        view.ColumnGroups.Add(New GridViewColumnGroup("Customer Contact"))
        view.ColumnGroups.Add(New GridViewColumnGroup("Details"))
        view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Address"))
        view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("Contact"))
        view.ColumnGroups(0).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(0).Rows(0).ColumnNames.Add("CompanyName")
        view.ColumnGroups(0).Rows(0).ColumnNames.Add("ContactName")
        view.ColumnGroups(0).Rows(0).ColumnNames.Add("ContactTitle")
        view.ColumnGroups(1).Groups(0).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(1).Groups(0).Rows(0).ColumnNames.Add("Address")
        view.ColumnGroups(1).Groups(0).Rows(0).ColumnNames.Add("City")
        view.ColumnGroups(1).Groups(0).Rows(0).ColumnNames.Add("Country")
        view.ColumnGroups(1).Groups(1).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(1).Groups(1).Rows(0).ColumnNames.Add("Phone")
        view.ColumnGroups(1).Groups(1).Rows(0).ColumnNames.Add("Fax")
        RadGridView1.ViewDefinition = view


        view.ColumnGroups(1).Groups.Last().IsVisible=False 


    End Sub
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments