Export Data to CSV from GridView
The Kettic GridView .NET component provides the support of exporting data from grid to CSV file. Moreover, it allows the users to customize the exported data by using the formatting events. To export the data to the CSV, we need to use the KetticData.dll assembly and include the C# namespaces to access to the types contained in KetticData, like Kettic.WinForms.Data and Kettic.WinForms.UI.Export.
How to Export Data from Grid to CSV in C#
To export the data from grid to CSV, we need to initialize the ExportToCSV C# class first. And the constructor will take the parameter, KetticGridView, which will be exported. The simple C# code below shows that how to initialize the ExportToCSV object.
After initializing the ExportToCSV C# class, we can use the FileExtension property to change the file extension, *.csv, for the exported file.
While we are going to export data in grid, the hidden columns and rows can be exported or not. This is accomplished through the properties, HiddenColumnOption and HiddenRowOption. There are two valid options available to the users, ExportAlways and DoNotExport. The ExportAsHidden option are not supported by CSV format.
The Kettic GridView .NET control offers the SummariesExportOption property to specify how to export summary items. There are four options available for selecting: ExportAll, ExportOnlyTop, ExportOnlyBottom, and DoNotExport. The default setting is ExportAll. The C# code below shows how to set the SummariesExportOption property.
After setting the above properties, we can export the data from grid to CSV file now. To export data from grid to CSV, we need to use the ApplyExport method included in the ExportToCSV object. Its valid parameter includes fileName which define the name of the exported csv file.
The Kettic GridView offers the CSVFormatCell event for the users to create formatting grid cell that will be exported. It is able to access to a single cell element to replace the actual value for all cells that is relevant to the exported KetticGridView. The following C# code shows how to handle the CSVFormatCell event.
The Kettic GridView offers the CSVTableCreated event for the users to use together with the public ApplyCustomCSVRow method. This allows the users to create and format new custom grid rows on the top of the csv file. The following C# code shows how to handle the CSVTableCreated event.
|
UI Controlsfor Windows Forms .NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI DesignWinForms UI Controls WinForms Buttons UI Control WinForms Calendar UI ControlWinForms Carousel UI ControlWinForms Chart UI ControlWinForms Clock UI ControlCommandBar UI ControlWinForms Dock UI ControlDesktop Alert UI ControlDropDown List UI ControlWinForms Editor UI ControlForms and Dialogs UI ControlWinForms GridView UI ControlGridView - Get Started in C#GridView - PropertiesGridView - ColumnGridView - RowGridView - CellsGridView - EditorsGridView - Context MenuGridView - Populating with DataGridView - Hierarchical GridGridView - SelectionGridView - ScrollingGridView - SortingGridView - GroupingGridView - FilteringGridView - Expression EditorInsert/ Update/ Delete RecordsGridView - View DefinitionTableColumn GroupGridView - Exporting DataExport to ExcelExport Data in a Group to ExcelExport to CSVExport to HTMLExport to PDFStyling and AppearanceThemeImageAlternating Row ColorGridView - LocalizationSave and Load LayoutGridView - Print SupportPrint StylePrint EventsWinForms ListView UI ControlWinForms Menu UI ControlWinForms ComboBox UI ControlWinForms PageView UI ControlPanels and Labels UI ControlWinForms Panorama UI ControlWinForms PDFViewer UI ControlWinForms Property Grid UI ControlWinForms Ribbon UI ControlWinForms PivotGrid UI ControlWinForms RichTextBox UI ControlWinForms Rotator UI ControlWinForms Scheduler UI ControlWinForms Shortcuts UI ControlWinForms SpellChecker UI ControlWinForms Track & Status UI ControlWinForms TreeView UI ControlWinForms Wizard UI ControlWinForms Test UI ControlWinForms Theme UI Control |