# Comparing FlexGrids

Migrate from ActiveX version to latest .NET version of FlexGrid control. The topic helps you know how to do it with minimum programming effort.

## Content

## VSFlexGrid (ActiveX) and C1FlexGrid (.NET)

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 <span data-popup-content="This class is available in both \u003ca href=\u0022/componentone/docs/win/online-flexgrid/\u0022\u003e.NET Framework\u003c/a\u003e and \u003ca href=\u0022/componentone/docs/win/online-flexgrid/\u0022\u003e.NET\u003c/a\u003e." data-popup-title="C1FlexGrid" data-popup-theme="ui-tooltip-green qtip-green">C1FlexGrid</span> 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.

>type=note
> **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 | <ol><li><strong>Rows</strong> and <strong>Cols</strong> properties are used to get or set the number of rows and columns.</li><li>VSFlexGrid uses the <strong>TextMatrix</strong> property to represent the rows and columns.</li></ol> For instance, in ActiveX, you would write: <br>`Dim r%, c% c = 1`<br>`For r = c1FlexGrid1.FixedRows To c1FlexGrid1.Rows - 1`<br>`Debug.Print c1FlexGrid1.TextMatrix(r,c)`<br>`Next` | <ol><li>In C1FlexGrid, <strong>Rows</strong> and <strong>Cols</strong> properties return the rows and column collections. The collections have read/write properties that return the number of elements and fixed elements in each collection.</li><li>C1FlexGrid uses indexers to represent rows and columns.</li></ol> For instance, in .NET, you would write: <br>`Dim r, c c = 1`<br>`For r = c1FlexGrid1.Rows.Fixed To c1FlexGrid1.Rows.Count - 1`<br>`Debug.Print(c1FlexGrid1(r, c))`<br>`Next` |
| 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: <br>`flex.Cell(flexcpPicture, 5, 5, 10, 10)`<br>`= theImage` | 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:<br>`Dim rg As CellRange`<br>`rg = c1FlexGrid1.GetCellRange(5,5,10,10)`<br>`rg.Image = theImage` |
| 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: <br>`c1FlexGrid1.Cols(2).DataType = GetType(Integer)`<br>`' Sets the value to 12`<br>`c1FlexGrid1(1, 2) = "12"`<br>`' Can not convert "hello" string to integer`<br>`' Fires the GridError event`<br>`' Retains the original value`<br>`c1FlexGrid1(2, 2) = "hello"` |
| 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: <br>`//Set the backcolor of second row`<br>`c1FlexGrid1.Cell(flexcpBackColor, 2, 0, 2,`<br>`c1FlexGrid1.Cols-1) = vbRed`<br>**Demerit**:<br>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: <br>`//Create a cell style`<br>`Dim redStyle As CellStyle = c1FlexGrid1.Styles`<br>`.Add("Red")`<br>`redStyle.BackColor = Color.Red`<br>`//Set the backcolor of second row`<br>`c1FlexGrid1.Rows(2).Style = redStyle`<br>**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: <br>`c1FlexGrid1.Styles("Red").ForeColor = Color.White`<br>`c1FlexGrid1.Styles("Red").Font = new Font("Arial", 9)` |
| |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. |
