ComponentOne provides ActiveX as well as .NET version of the FlexGrid control. While the ActiveX version is known as "VSFlexGrid", the .NET version is shipped in the name of "C1FlexGrid". Being a .NET version, C1FlexGrid came later into the picture and instead of porting from the already existing VSFlexGrid, we decided to create a brand new grid control, written from the ground up in C#, with the same design principles but with a new object model that is more modern, clean, and powerful than the one in the ActiveX control.
This section caters to original users of the VSFlexGrid control who want to migrate their applications from ActiveX to the .NET version, that is, the C1FlexGrid control. To facilitate the hassle-free migration and a smooth learning curve, the .NET version provides the C1FlexGridClassic control that derives from the C1FlexGrid class and provides an object model that is virtually identical to the VSFlexGrid control. The C1FlexGridClassic control is available in the form of a product sample "Classic", so that you may know exactly how to use the new object model. This sample can also be used as a reference for creating the custom grid controls based on the C1FlexGrid class.
Note: The Classic sample is located at \Documents\ComponentOne Samples\WinForms\v4.5.2\C1FlexGrid\CS on your system, if you have installed the samples while installing WinForms Edition using ComponentOneControlPanel.exe.
For users creating new applications, we recommend using the new C1FlexGrid control. However, for the users who are porting their existing applications from ActiveX to .NET, we recommend using the C1FlexGridClassic control to minimize the programming effort. Following table highlights some of the key differences between VSFlexGrid and C1FlexGrid:
VSFlexGrid (ActiveX) | C1FlexGrid (.NET) | |
Rows/Cols |
For instance, in ActiveX, you would write:
|
For instance, in .NET, you would write:
|
Cell/Cell range |
The Cell property is one of the most powerful elements of the VSFlexGrid object model. It allows you to get or set any property of any cell or cell range with a single command. Using a single property means using variants, and this prevents the compiler from catching many subtle problems in case you make mistakes while coding. For instance, in ActiveX, you would write:
|
In C1FlexGrid, CellRange object has replaced the Cell property to expose type-safe properties and methods for accessing cell range. So, if variable theImage contained a string instead of an image, you get a compiler error and not a runtime error. Also, you get command-completion when writing the code because the types for each property are known. For instance, in .NET, you would write:
|
Typed Columns | In the ActiveX version, the ColDataType property allows you to set the type of data that each column contains. This information is used mainly for sorting columns that contain dates or numbers. |
In the .NET version, Cols[i].DataType property determines the type of data the column holds. By default, the DataType property for all columns is set to "object", that is you can store any type of data in any column. You can set the data type to specific types, however, the grid tries to coerce any data stored in the grid to the proper type. For instance, in .NET, you would write:
|
Styles |
In VSFlexGrid, you can customize the appearance of individual cells or cell ranges using the Cell property. For instance, in ActiveX, you would write:
Demerit: To change the appearance of all red cells, you need to clear all styles and start again or you need to scan for red cells and then change their appearance. |
In C1FlexGrid, cell appearance can be customized using the CellStyle object. For instance, in .NET, you would write:
Merit: The main advantage of this approach is that the new style is an object that can be changed or assigned to new ranges. For instance, to change the fore-color and text font of red cells, you would write:
|
The VSFlexGrid control had many properties that affected the way the grid was displayed (e.g. BackColor, BackColorAlternate, BackColorBkg, BackColorFixed, BackColorFrozen, BackColorSel, and so on). | The C1FlexGrid control replaces all these properties with a collection of CellStyle objects, so you can write something like Styles.Fixed.BackColor or Styles.Highlight.ForeColor. This makes the object model simpler, more consistent, and more powerful. You can change the built-in styles or define your own, and assign them to rows, columns, or arbitrary cell ranges. |