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

Exporting only checked nodes of Radtreeview

1 Answer 96 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
George C.
Top achievements
Rank 2
Iron
Veteran
George C. asked on 03 Jan 2020, 03:34 PM

Greetings,

With the code below (from Telerik Winforms demo app), it is possible to export radtreeview data to different formats.

 

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Telerik.WinControls
Imports Telerik.WinControls.Enumerations
Imports Telerik.WinControls.Export
Imports Telerik.WinControls.UI
Imports Telerik.WinControls.UI.Export
 
Namespace ExportWithDpl.TreeView
    Public Partial Class Form1
        Inherits RadForm
        Public Sub New()
            InitializeComponent()
            Me.LoadTreeData()
            Me.WireEvents()
            Me.SetupInitialSettings()
 
            If Program.themeName <> "" Then 'set the example theme to the same theme QSF uses
                ThemeResolutionService.ApplicationThemeName = Program.themeName
            Else
                ThemeResolutionService.ApplicationThemeName = "TelerikMetro" 'set default theme
            End If
        End Sub
 
        Private Sub LoadTreeData()
            Me.radTreeView1.Nodes.Add(New RadTreeNode("Personal Folders", Image.FromFile("..\TreeView\Images\Root.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Deleted Items", Image.FromFile("..\TreeView\Images\RecycleBin.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Drafts", Image.FromFile("..\TreeView\Images\DraftFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Inbox", Image.FromFile("..\TreeView\Images\InboxFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Junk E-mails", Image.FromFile("..\TreeView\Images\JunkFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Outbox", Image.FromFile("..\TreeView\Images\OutboxFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Sent Items", Image.FromFile("..\TreeView\Images\SentFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("Search Folder", Image.FromFile("..\TreeView\Images\SearchFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes.Add(New RadTreeNode("New Item", Image.FromFile("..\TreeView\Images\SentFolder.png")))
 
            Me.radTreeView1.Nodes(0).Nodes(2).Nodes.Add(New RadTreeNode("Folders", Image.FromFile("..\TreeView\Images\Folder1.png")))
            Me.radTreeView1.Nodes(0).Nodes(6).Nodes.Add(New RadTreeNode("From Follow up", Image.FromFile("..\TreeView\Images\SearchFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes(6).Nodes.Add(New RadTreeNode("Large Mail", Image.FromFile("..\TreeView\Images\SearchFolder.png")))
            Me.radTreeView1.Nodes(0).Nodes(6).Nodes.Add(New RadTreeNode("Unread Mail", Image.FromFile("..\TreeView\Images\SearchFolder.png")))
 
            Me.radTreeView1.TreeViewElement.AutoSizeItems = False
            Me.radTreeView1.ItemHeight = 25
            Me.radTreeView1.ExpandAll()
        End Sub
 
        Private Sub WireEvents()
            AddHandler Me.exportButton.Click, AddressOf exportButton_Click
            AddHandler Me.allowAlternatingRowColorCheckBox.ToggleStateChanged, AddressOf allowAlternatingRowColorCheckBox_ToggleStateChanged
        End Sub
 
        Private Sub SetupInitialSettings()
            Me.exportVisualSettingsCheckBox.ToggleState = ToggleState.On
            Me.exportImagesCheckBox.ToggleState = ToggleState.On
            Me.groupChildNodesCheckBox.ToggleState = ToggleState.On
            Me.exportFormatXlsxRadioButton.ToggleState = ToggleState.On
            Me.collapsedOptionExportAlwaysRadioButton.ToggleState = ToggleState.On
        End Sub
 
        Private Sub allowAlternatingRowColorCheckBox_ToggleStateChanged(ByVal sender As Object, ByVal args As StateChangedEventArgs)
            Me.radTreeView1.TreeViewElement.AllowAlternatingRowColor = args.ToggleState = ToggleState.On
        End Sub
 
        Private Sub exportButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim exporter As TreeViewSpreadExport = New TreeViewSpreadExport(Me.radTreeView1)
 
            Dim dialog As SaveFileDialog = New SaveFileDialog()
            dialog.FileName = "exportedFile"
            If Me.exportFormatXlsxRadioButton.ToggleState = ToggleState.On Then
                exporter.ExportFormat = SpreadExportFormat.Xlsx
                dialog.Filter = "xlsx files (*.xlsx)|*.xlsx|All files (*.*)|*.*"
            ElseIf Me.exportFormatPdfRadioButton.ToggleState = ToggleState.On Then
                exporter.ExportFormat = SpreadExportFormat.Pdf
                dialog.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*"
            ElseIf Me.exportFormatCsvRadioButton.ToggleState = ToggleState.On Then
                exporter.ExportFormat = SpreadExportFormat.Csv
                dialog.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*"
            ElseIf Me.exportFormatTxtRadioButton.ToggleState = ToggleState.On Then
                exporter.ExportFormat = SpreadExportFormat.Txt
                dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            End If
 
            If dialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                If Me.customizeVisualSettingsCheckBox.ToggleState = ToggleState.On Then
                    AddHandler exporter.CellFormatting, AddressOf exporter_CellFormatting
                End If
 
                exporter.ExportVisualSettings = Me.exportVisualSettingsCheckBox.ToggleState = ToggleState.On
                exporter.ExportImages = Me.exportImagesCheckBox.ToggleState = ToggleState.On
                exporter.ExportChildNodesGrouped = Me.groupChildNodesCheckBox.ToggleState = ToggleState.On
 
                If Me.collapsedOptionExportAlwaysRadioButton.ToggleState = ToggleState.On Then
                    exporter.CollapsedNodeOption = HiddenOption.ExportAlways
                ElseIf Me.collapsedOptionDoNotExportRadioButton.ToggleState = ToggleState.On Then
                    exporter.CollapsedNodeOption = HiddenOption.DoNotExport
                ElseIf Me.collapsedOptionExportAsHiddenRadioButton.ToggleState = ToggleState.On Then
                    exporter.CollapsedNodeOption = HiddenOption.ExportAsHidden
                End If
 
                Dim renderer As SpreadExportRenderer = New SpreadExportRenderer()
                exporter.RunExport(dialog.FileName, renderer)
            End If
        End Sub
 
        Private Sub exporter_CellFormatting(ByVal sender As Object, ByVal e As TreeViewSpreadExportCellFormattingEventArgs)
            If e.TreeNode.Nodes.Count > 0 Then
                e.ExportCell.BackColor = Color.LightBlue
                e.ExportCell.ForeColor = Color.DarkMagenta
                e.ExportCell.Font = New Font("SegoeUI", 12, FontStyle.Underline)
            Else
                e.ExportCell.BackColor = Color.LightYellow
            End If
        End Sub
    End Class
End Namespace

 

How can I modify the code to only include Checked nodes of the radtreeview when exporting ,for example, to Excel format ?

(checkbox value of the radtreeview is set to True)

 

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Jan 2020, 12:00 PM
Hello, George,   

There is no automatic way to export only a subset of nodes that are checked in RadTreeView. In order to achieve it, it is necessary to use a dummy RadTreeView programmatically populated with the checked nodes from the original RadTreeView. Then, you can simply export the dummy RadTreeView.

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Treeview
Asked by
George C.
Top achievements
Rank 2
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or