FlexGrid for WinForms | ComponentOne
Feature Comparison / Comparing FlexGrids
In This Topic
    Comparing FlexGrids
    In This Topic

    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 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
    1. Rows and Cols properties are used to get or set the number of rows and columns.
    2. VSFlexGrid uses the TextMatrix property to represent the rows and columns.

    For instance, in ActiveX, you would write:

    Dim r%, c% c = 1
    For r = c1FlexGrid1.FixedRows To c1FlexGrid1.Rows - 1
    Debug.Print c1FlexGrid1.TextMatrix(r,c)
    Next

    1. In C1FlexGrid, Rows and Cols 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.
    2. C1FlexGrid uses indexers to represent rows and columns.

    For instance, in .NET, you would write:

    Dim r, c c = 1
    For r = c1FlexGrid1.Rows.Fixed To c1FlexGrid1.Rows.Count - 1
    Debug.Print(c1FlexGrid1(r, c))
    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:

    flex.Cell(flexcpPicture, 5, 5, 10, 10)
    = 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:

    Dim rg As CellRange
    rg = c1FlexGrid1.GetCellRange(5,5,10,10)
    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:

    c1FlexGrid1.Cols(2).DataType = GetType(Integer)
    ' Sets the value to 12
    c1FlexGrid1(1, 2) = "12"
    ' Can not convert "hello" string to integer
    ' Fires the GridError event
    ' Retains the original value
    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:

    //Set the backcolor of second row
    c1FlexGrid1.Cell(flexcpBackColor, 2, 0, 2,
    c1FlexGrid1.Cols-1) = vbRed

    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:

    //Create a cell style
    Dim redStyle As CellStyle = c1FlexGrid1.Styles
    .Add("Red")
    redStyle.BackColor = Color.Red
    //Set the backcolor of second row
    c1FlexGrid1.Rows(2).Style = redStyle

    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:

    c1FlexGrid1.Styles("Red").ForeColor = Color.White
    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.