Developers Guide
Developers Guide
Developers’ Guide to
DataGridView Extension 1.1.1
Revision date 27 February 2008
Page 1 of 21
DataGridView Extension 1.1.1
Contents
1. General ................................................................................................................................... 4
1.1. Installation structure ....................................................................................................... 4
1.2. Assemblies ....................................................................................................................... 4
2. Common ................................................................................................................................. 5
2.1. Supported data sources................................................................................................ 5
2.2. Manage grid view programmatically ......................................................................... 5
2.3. Open settings editor for a managed grid view ......................................................... 6
2.4. Explicit refresh of a managed grid view...................................................................... 6
2.5. Changing Xml persistence folder................................................................................. 7
2.6. Custom columns ............................................................................................................. 7
3. Export ....................................................................................................................................... 7
3.1. MS Excel ........................................................................................................................... 8
3.2. Html................................................................................................................................... 8
3.3. Pdf..................................................................................................................................... 9
3.4. Export using the default settings................................................................................... 9
3.5. Export using the exporting manager ......................................................................... 10
3.6. Events and error handling ........................................................................................... 11
3.7. Export using the appropriate export settings editor dialog.................................... 11
3.8. Creating custom exporter ........................................................................................... 12
3.9. Changing exporters folder .......................................................................................... 12
4. Security .................................................................................................................................. 13
4.1. Default permissions for all grid view controls in the application............................ 13
4.2. Default permissions for all columns in the application............................................ 14
4.3. Permissions for a particular grid view control ........................................................... 14
4.4. Permissions for a particular column ........................................................................... 15
4.5. General permissions for the extension....................................................................... 16
5. Find......................................................................................................................................... 17
5.1. How to find specific cell value ................................................................................... 17
Page 2 of 21
DataGridView Extension 1.1.1
Page 3 of 21
DataGridView Extension 1.1.1
1. General
DataGridView Extension is a component that extends the basic DataGridView control (provided
with .NET 2.0 Framework) with additional functionality without inheritance.
DataGridView Extension allows both developers and end users to control specific features of the
DataGridView control in runtime environment. As part of these features, the appearance and
behavior of the control could be modified also.
DataGridView Extension provides additional functionality, such as printing, exporting of data and
visualization to MS Excel, Pdf documents and Html pages, searching for text in the control and
theme management.
Major functionality of DataGridView Extension is that it allows persistence and export/import of all
changes made to the control: its columns widths, ordering, headers width and height,
appearance and behavior.
DataGridView Extension has the ability to manage multiple DataGridView controls in a single
project and to store all user settings for every and each of them.
DataGridView Extension allows saving of themes defined by the customer. Themes greatly
reduce the labor needed to set a professional looking application. Customers can change the
entire application’s look and feel with a single click by changing the default theme. Themes can
be saved in different applications and even backup.
The DataGridView Extension comes with a set of custom column types that will give the
developer additional functionalities of the grid itself.
\v1.1
\Bin - Contains all DLLs you need to develop applications using DGV Extension;
\Help - Contains the end-user manual as Pdf file;
\PIAs - Contains the Primary Interop Assemblies (PIAs) and the registry files needed for the export to MS
Excel;
\Samples
\Demo - Demo application DLLs and executable
\CSharp - VS.2005 sample project written in C#
\VisualBasic.Net - VS.2005 sample project written in VisualBasic.Net
1.2. Assemblies
- ‘DataGridViewExtension.dll’ – This is the main assembly of the DataGridView Extension. It
contains some major functionality such as Print, Find, Themes support, Xml persistence
and others.
- ‘DataGridViewExtension.XmlSerializers.dll’ – Xml persistence optimization assembly; this
assembly is optional and can be removed freely but keep in mind that it reduces the
initial loading time for all persisted Xml settings drastically.
Page 4 of 21
DataGridView Extension 1.1.1
For more information about the assemblies you have to reference from your projects please read
‘To which assemblies do I have to add references in my project’ in the FAQ section.
2. Common
Many of the functionalities developed for the DataGridView Extension are accessible not only
runtime via the visual editors but also through an API.
Tip: If you have two or more grid controls in your application that visualize the same type of data
i.e. Clients they will share one Xml settings file thus one visual representation, if you set one and
the same name to both controls i.e. ‘dgrClients’.
Add reference to the main assembly ‘DataGridViewExtension.dll’ and all export DLLs you wish to
be supported by the extension in your application like ‘DGVEExcelExporting.dll’.
C#
using CompletIT.Windows.DataGridViewExtension;
VB.NET
Page 5 of 21
DataGridView Extension 1.1.1
Imports CompletIT.Windows.DataGridViewExtension
After a grid has been managed either manually or design-time by the extension, its settings
editor can be opened in the way shown bellow.
C#
using CompletIT.Windows.DataGridViewExtension;
VB.NET
Imports CompletIT.Windows.DataGridViewExtension
C#
using CompletIT.Windows.DataGridViewExtension;
VB.NET
Imports CompletIT.Windows.DataGridViewExtension
Page 6 of 21
DataGridView Extension 1.1.1
C#
using CompletIT.Windows.DataGridViewExtension;
using CompletIT.Windows.DataGridViewExtension.Persistence;
using CompletIT.Windows.DataGridViewExtension.Persistence.Xml;
VB.NET
Imports CompletIT.Windows.DataGridViewExtension
Imports CompletIT.Windows.DataGridViewExtension.Persistence
Imports CompletIT.Windows.DataGridViewExtension.Persistence.Xml
Note: The custom columns will be available in “Add column” dialog of Visual Studio after you
add reference to the assembly ‘DataGridViewExtension.dll’.
3. Export
The export mechanism of the DataGridView Extension is developed in a way that allows usage of
the different exports either as part of the extension application or as separate exports accessed
programmatically. The system is open and you can develop your own exports to any desired file
formats in just a few steps described in more details at the end of this section.
Page 7 of 21
DataGridView Extension 1.1.1
For more information you can read ‘How does the export functionality work’ in the FAQ section.
Note: If you want to export the content of a DataGridView control using the API, you do not
have to manage it; just pass it as a parameter to the appropriate exporter.
3.1. MS Excel
Add reference to the main assembly ‘DataGridViewExtension.dll’ and export DLL
‘DGVEExcelExporting.dll’.
C#
using CompletIT.Windows.Forms.Export.Excel;
VB.NET
Imports CompletIT.Windows.Forms.Export.Excel
3.2. Html
Add reference to the main assembly ‘DataGridViewExtension.dll’ and export DLL
‘DGVEHtmlExporting.dll’.
C#
using CompletIT.Windows.Forms.Export.Html;
VB.NET
Imports CompletIT.Windows.Forms.Export.Excel
Page 8 of 21
DataGridView Extension 1.1.1
3.3. Pdf
Add reference to the main assembly ‘DataGridViewExtension.dll’ and export DLL
‘DGVEPdfExporting.dll’.
C#
using CompletIT.Windows.Forms.Export.Pdf;
VB.NET
Imports CompletIT.Windows.Forms.Export.Pdf
C#
using CompletIT.Windows.Forms.Export.Export.Pdf;
pdfExporter.Export( dataGridView );
VB.NET
Imports CompletIT.Windows.Forms.Export.Export.Pdf
PdfExporter.Export( Me.DataGridViewControl )
Page 9 of 21
DataGridView Extension 1.1.1
C#
using CompletIT.Windows.Forms.Export.Export;
using CompletIT.Windows.Forms.Export.Export.Excel;
VB.NET
Imports CompletIT.Windows.Forms.Export.Export
Imports CompletIT.Windows.Forms.Export.Export.Excel
or
C#
using CompletIT.Windows.Forms.Export.Export;
using CompletIT.Windows.Forms.Export.Export.Excel;
VB.NET
Imports CompletIT.Windows.Forms.Export.Export
Imports CompletIT.Windows.Forms.Export.Export.Excel
As you can see the difference is that in the first example you do not have to pass
settings to the exporting manager, but instead of this the last persisted settings will be
used.
You can set a value whether the progress form should be visible or not during the export
process.
C#
using CompletIT.Windows.Forms.Export.Export;
Page 10 of 21
DataGridView Extension 1.1.1
DGVEExportingManager.ShowProgressForm = true;
VB.NET
Imports CompletIT.Windows.Forms.Export.Export
DGVEExportingManager.ShowProgressForm = True
List of the settings editor controls with their full names and the assemblies they belong to.
The sample code below show how to popup the settings editor control for Pdf export settings.
You can use the same approach for MS Excel and Html export settings editors.
C#
using CompletIT.Windows.Forms.Export.Export;
using CompletIT.Windows.Forms.Export.Export.Pdf;
VB.NET
Imports CompletIT.Windows.Forms.Export.Export
Imports CompletIT.Windows.Forms.Export.Export.Pdf
Page 11 of 21
DataGridView Extension 1.1.1
For example of custom exporter, please refer to the sample application shipped with the
Extension distribution.
Tip: One assembly can contain more than one exporter classes.
C#
using CompletIT.Windows.Forms.Export.Export;
DGVEExportingManager.ExportersDirectoryName = "C:\\Exporters";
VB.NET
Imports CompletIT.Windows.Forms.Export.Export
DGVEExportingManager.ExportersDirectoryName = "C:\\Exporters"
Page 12 of 21
DataGridView Extension 1.1.1
4. Security
DataGridView Extension has built in security permissions mechanism, which allows you to prevent
changes of some editable properties in the user interface by the end-user of your application.
When you restrict the access to a specific property the corresponding user control(s) will be
disabled and thus the user will not be able to change it. For example you can restrict the access
to the read-only property for all columns so it cannot be modified.
There are two levels of permissions:
- Default – applied to all grid view controls and columns in your application;
- Specific - for a particular grid view control or a column (override the Default). Both grid
view and column controls are recognized by their names (Name property).
It is important to remark that the specific permissions have higher priority than the default
permissions. This means that if you explicitly restrict the access to a property in the default
permissions and allow it in the specific permissions for a particular grid view or column then the
user will be able to change it only for that particular grid view or column, because the specific
permissions have the final word.
Note: Keep in mind that the permissions in a single application are shared and are not bound to
a specific instance of the DataGridView Extension. This means that you can have several
instances of the extension in your application but all of them will use the same permissions set you
have defined elsewhere in your application.
4.1. Default permissions for all grid view controls in the application
You can define default permissions for the properties that can be modified in the user interface
for all grid view controls in your application.
Default grid view permissions can be overridden by the permissions explicitly defined for a
specific grid view control.
C#
using CompletIT.Windows.Forms.Permissions;
//The user will not be able to change the theme for any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions[ GridViewProperty.ChangeTheme ] = false;
//The user will not be able to export any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions[ GridViewProperty.Export ] = false;
//The user will not be able to search in any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions[ GridViewProperty.Find ] = false;
//The user will not be able to print any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions[ GridViewProperty.Print ] = false;
//The user will not be able to change the general settings in any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions[ GridViewProperty.EditGeneralSettings ] = false;
//Set other permissions here…
VB.NET
Imports CompletIT.Windows.Forms.Permissions
‘The user will not be able to change the theme for any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions( GridViewProperty.ChangeTheme ) = False
‘The user will not be able to export any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions( GridViewProperty.Export ) = False
Page 13 of 21
DataGridView Extension 1.1.1
‘The user will not be able to search in any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions( GridViewProperty.Find ) = False
‘The user will not be able to print any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions( GridViewProperty.Print ) = False
‘The user will not be able to change the general settings in any of the grids in your application
DGVEPermissions.DefaultGridViewPermissions( GridViewProperty. EditGeneralSettings ) = False
‘Set other permissions here…
Default columns permissions can be overridden by the permissions explicitly defined for a specific
column.
C#
using CompletIT.Windows.Forms.Permissions;
//The user will not be able to edit any of the extension column properties in your application
DGVEPermissions.DefaultGridViewPermissions.ColumnPermissions[ ColumnProperty.Edit ] = false;
//The user will not be able to change the read-only property for any column in your application
DGVEPermissions. DefaultGridViewPermissions.ColumnPermissions[ ColumnProperty.ChangeReadOnly ] =
false;
//The user will not be able to change the frozen property for any column in your application
DGVEPermissions. DefaultGridViewPermissions.ColumnPermissions[ ColumnProperty.ChangeFrozen ] = false;
//The user will not be able to rename any column in your application
DGVEPermissions. DefaultGridViewPermissions.ColumnPermissions[ ColumnProperty.Rename ] = false;
//Set other column permissions here…
VB.NET
Imports CompletIT.Windows.Forms.Permissions
‘The user will not be able to edit any of the extension column properties in your application
DGVEPermissions. DefaultGridViewPermissions. ColumnPermissions( ColumnProperty.Edit ) = False
‘The user will not be able to change the read-only property for any column in your application
DGVEPermissions. DefaultGridViewPermissions. ColumnPermissions( ColumnProperty.ChangeReadOnly ) =
False
‘The user will not be able to change the frozen property for any column in your application
DGVEPermissions. DefaultGridViewPermissions. ColumnPermissions( ColumnProperty.ChangeFrozen ) = False
‘The user will not be able to rename any column in your application
DGVEPermissions. DefaultGridViewPermissions. ColumnPermissions( ColumnProperty. Rename ) = False
‘Set other column permissions here…
The explicitly defined permissions for a particular grid view override the default permissions.
C#
using CompletIT.Windows.Forms.Permissions;
Page 14 of 21
DataGridView Extension 1.1.1
//The user will not be able to change the theme of the grid view
gridPermissions[ GridViewProperty.ChangeTheme ] = false;
//The user will not be able to export the content of the grid view
gridPermissions[ GridViewProperty.Export ] = false;
//The user will not be able to search in the grid view
gridPermissions[ GridViewProperty.Find ] = false;
//The user will not be able to print the grid view
gridPermissions[ GridViewProperty.Print ] = false;
//The user will not be able to change the general settings of the grid view
gridPermissions[ GridViewProperty.EditGeneralSettings ] = false;
VB.NET
Imports CompletIT.Windows.Forms.Permissions
'The user will not be able to change the theme of the grid view
gridPermissions(GridViewProperty.ChangeTheme) = False
'The user will not be able to export the content of the grid view
gridPermissions(GridViewProperty.Export) = False
'The user will not be able to search in the grid view
gridPermissions(GridViewProperty.Find) = False
'The user will not be able to print the grid view
gridPermissions(GridViewProperty.Print) = False
'The user will not be able to change the general settings of the grid view
gridPermissions(GridViewProperty.EditGeneralSettings) = False
The explicitly defined permissions for a particular grid view column override the default column
permissions.
C#
using CompletIT.Windows.Forms.Permissions;
//The user will not be able to change the read-only state of the column
columnPermissions[ ColumnProperty.ChangeReadOnly ] = false;
//The user will not be able to change the frozen state of the column
columnPermissions[ ColumnProperty.ChangeFrozen ] = false;
Page 15 of 21
DataGridView Extension 1.1.1
VB.NET
Imports CompletIT.Windows.Forms.Permissions
//The user will not be able to change the read-only state of the column
columnPermissions( ColumnProperty.ChangeReadOnly ) = False
//The user will not be able to change the frozen state of the column
columnPermissions( ColumnProperty.ChangeFrozen ) = False
//The user will not be able to rename the column
columnPermissions( ColumnProperty.Rename ) = False
//Set other column permissions here…
C#
using CompletIT.Windows.Forms.Permissions;
//The user will not be able to open the settings editor for any grid view in the application
DGVEPermissions.ExtensionPermissions[ ExtensionProperty.OpenSettingsEditor ] = false;
//The user will not be able to export themes
DGVEPermissions.ExtensionPermissions[ ColumnProperty.ExportThemes ] = false;
//The user will not be able to import themes
DGVEPermissions.ExtensionPermissions[ ColumnProperty.ImportThemes ] = false;
//Set other extension permissions here…
VB.NET
Imports CompletIT.Windows.Forms.Permissions
‘The user will not be able to open the settings editor for any grid view in the application
DGVEPermissions.ExtensionPermissions( ExtensionProperty.OpenSettingsEditor ) = False
‘The user will not be able to export themes
DGVEPermissions.ExtensionPermissions( ColumnProperty.ExportThemes ) = False
‘The user will not be able to import themes
DGVEPermissions.ExtensionPermissions( ColumnProperty.ImportThemes ) = False
//Set other extension permissions here…
Page 16 of 21
DataGridView Extension 1.1.1
5. Find
C#
using CompletIT.Windows.DataGridViewExtension;
VB.NET
Imports CompletIT.Windows.DataGridViewExtension
C#
using CompletIT.Windows.DataGridViewExtension;
VB.NET
Imports CompletIT.Windows.DataGridViewExtension
6. Print
The print engine of the DataGridView Extension is developed in a way which allows it’s usage as
a separate component.
Page 17 of 21
DataGridView Extension 1.1.1
Note: If you want to print the content of a DataGridView control, you do not have to
manage/extend it; just pass it as a parameter to the appropriate print method of the print
engine.
C#
using CompletIT.Windows.Forms.Printing;
VB.NET
Imports CompletIT.Windows.Forms.Printing
C#
using CompletIT.Windows.Forms.Printing;
VB.NET
Imports CompletIT.Windows.Forms.Printing
C#
using CompletIT.Windows.Forms.Printing;
Page 18 of 21
DataGridView Extension 1.1.1
VB.NET
Imports CompletIT.Windows.Forms.Printing
7. FAQ
7.2. Does DataGridView Extension component inherit the standard DataGridView control?
No, DataGridView Extension component just decorates the standard DataGridView control
provided in .NET 2.0 Framework without any inheritance and with just single line of code.
7.6. What are the requirements in order to have a DataGridView control managed by the
DataGridView Extension?
There are two things you have to ensure: the first is a valid Name set to the DataGridView control
and the second is permission to write the Xml files to the hard drive.
Page 19 of 21
DataGridView Extension 1.1.1
7.15. The export to Excel does not work what should I do?
The export to MS Excel is COM based and it requires the following PIAs:
‘Microsoft.Office.Interop.Excel.dll’, ‘Microsoft.Vbe.Interop.dll’ and ‘Office.dll’.
Check whether they are registered in your GAC (Global Assembly Cache) or exist in the folder
where all assemblies of the Extension reside.
If you have to register the PIAs in your GAC use the register files from
‘<InstallationPath>\v1.1\PIAs’ shipped with the distribution of the DataGridView Extension.
Page 20 of 21
DataGridView Extension 1.1.1
7.17. How many DataGridView controls can be managed by a single instance of the Extension?
One instance of the DataGridView Extension can manage as many DataGridView controls as
you want. There is no memory overhead if you create separate instance for each DataGridView
control in your application.
7.18. How many instance of the extension can I have in single .NET application?
You can have as many instances of the DataGridView Extension component as you want within
an application, but remember that a DataGridView control should be managed by only one
instance of the Extension.
7.19. Why the colors of my column and row headers are not applied although I have changed them?
If you want to change the colors of the row and column headers you have to ensure that the
option ‘Use Windows Visual Styles’ is not checked in the Header Styles editor - by default this
option is checked which means that all headers are using the default colors defined by the
system.
Page 21 of 21