Hide Columns If Group Is Hidden When Exporting To Excel

4 posts, 0 answers
  1. Shane
    Shane avatar
    9 posts
    Member since:
    Feb 2016

    Posted 26 Feb Link to this post

    I have a RadGridView which I've used the property builder to add several groups to.When I hide the group, it hides the columns within the group on screen, however when I export the grid to excel, the columns within the group are still visible.

    Is there anyway of fixing this so that if the group is hidden, the columns within the group are not exported?

    I already have:

            Dim exporter As ExportToExcelML = New ExportToExcelML(Me.grid)
            exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport
            exporter.SheetName = "Export"
            exporter.SummariesExportOption = SummariesOption.DoNotExport
            Dim filename As String = "C:\Export.xls"
            exporter.RunExport(filename)

    Thanks in advance for any help.
  2. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 26 Feb Link to this post

    Hello Shane,

    Thank you for writing.

    The following article shows how you can export a particular group only: Export Data in a Group to Excel.

    In addition, you may try our new spread export functionality: Spread export.

    I hope this helps. Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Shane
    Shane avatar
    9 posts
    Member since:
    Feb 2016

    Posted 26 Feb Link to this post

    Hi,

     

    These both appear to be about grouping rows? I have Columns grouped using the "Property Builder" tool on the radgridview. For example, I have:

    GROUP 1 - Columns 1, 2, 3

    GROUP 2 - Columns 4, 5, 6, 7

    GROUP 3 - Columns 8, 9, 10

    If I hide group 2, the export still exports columns 4, 5, 6 and 7. If I hide the cells through (not the group), they do not export.

    I've tried this before the export:

     If Me.grid.Columns("GROUP1").IsVisible = False Then
                Me.grid.Columns("Column4").IsVisible = False
                Me.grid.Columns("Column5").IsVisible = False
                Me.grid.Columns("Column6").IsVisible = False
                Me.grid.Columns("Column7").IsVisible = False

    end if

    However it throws an error of "NullReferenceException was unhandled. Object reference not set to an instance of an object". I think this may be as GROUP1 isn't a column and therefore I can't check if it is visible or not. 

    So basically, I need to know how to check if a group of columns is visible or not?

    Thanks, Shane

     

  5. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 26 Feb Link to this post

    Hi Shane,

    Thank you for writing back.

    You are using ColumnGroupsViewDefinition and in this case, you can check if particular group is visible like this:
    Dim view = TryCast(radGridView1.ViewDefinition, ColumnGroupsViewDefinition)
     
    If Not view.ColumnGroups(1).IsVisible Then
        radGridView1.Columns(4).IsVisible = False
        radGridView1.Columns(5).IsVisible = False
    End If

    Let me know if I can assist you further.
     
    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top