True DBGrid for WinForms | ComponentOne
Working with Objects and Collection / Objects
In This Topic
    Objects
    In This Topic

    TrueDbGrid provides a rich set of properties, methods, and events that enable you to develop sophisticated database applications.

    Objects and collections that refer to visual entities, such as columns, can be customized in the designer or in code. Objects and collections that refer to abstract entities, such as arrays and bookmarks are only available in code.

    Two controls are available in the .NET Toolbox for addition into a project:

    Control Description
    C1TrueDbGrid

    TrueDBGrid for WinForms grid control.

    The C1TrueDBGrid control is the primary object of TrueDBGrid for WinForms. Use its C1DataColumnCollection and C1DisplayColumnCollection objects to create, access, and modify the column objects that define the mappings between the grid's physical columns and the underlying database fields. Using its SplitCollection object, the grid can be divided into multiple horizontal or vertical panes to provide different views of the same data source.

    C1TrueDBDropDown

    True DBGrid for WinForms drop-down box control.

    The C1TrueDBDropDown control, which is a subset of the C1TrueDBGrid control, is used as a multicolumn drop-down list box for a grid column. The C1TrueDBDropDown control cannot be used as a standalone control. In the designer, place a C1TrueDBDropDown control on a form just as you would a C1TrueDBGrid control. However, the drop-down control will be invisible at run time unless it is attached to a C1DataColumn object of a C1TrueDBGrid control. To use the drop-down control, set the DropDown property of a grid column to the name of a C1TrueDBDropDown control at either in the designer or in code. At run time, when the user clicks the in-cell button for that column, the C1TrueDBDropDown control will appear below the grid's current cell. If the user selects an item from the drop-down control, the grid's current cell is updated. The C1TrueDBDropDown control also supports incremental search.

    The namespace for TrueDBGrid for WinForms also contains definitions for the following objects.

    Object Description
    C1DataColumn

    Represents a column of data within a grid.

    Each column within a C1TrueDBGrid or C1TrueDBDropDown control is represented by two column objects, one global and one split-specific. All of the properties related to data access and formatting are contained under the C1DataColumn object. The properties of the C1DataColumn object are global in scope; changing a C1DataColumn property changes that value for all columns, even across splits. The C1DataColumn object can be accessed as follows:

    To write code in Visual Basic

    VB
    Copy Code
    Me.C1TrueDBGrid1.Columns(0).Caption = "Region"
    

    To write code in C#

    C#
    Copy Code
    this.c1TrueDBGrid1.Columns[0].Caption = "Region";
    
    C1DisplayColumn

    Represents a column of data relative to a split.

    Each split within the grid contains at least one C1DisplayColumn object. All of the properties related to a column's display are contained under this object. Unlike the C1DataColumn properties, the properties of the C1DisplayColumn object are split-specific. Changing a C1DisplayColumn property will change that value for only the specified column inside the specified split. The object can be accessed as follows:

    To write code in Visual Basic

    VB
    Copy Code
    Me.C1TrueDBGrid1.Splits(0,0).DisplayColumns(0).Style.ForeColor = System.Drawing.Color.Blue
    

    To write code in C#

    C#
    Copy Code
    this.c1TrueDBGrid1.Splits[0,0].DisplayColumns[0].Style.ForeColor = System.Drawing.Color.Blue;
    
    GridLines

    Represents the gridlines which separate items in the grid.

    The GridLines object is used to specify characteristics of the ColumnDivider and RowDivider properties. Both the color and style of the column and row lines can be manipulated at run time or design time through the use of the GridLines object.

    HBar

    Represents the horizontal scroll bar and its properties.

    The HBar object is used to specify properties of the horizontal scrollbar. Through the use of the HScrollBar property, the developer can specify the width of the scroll bar, and whether is shows up automatically or not at all.

    PrintPreviewWinSettings

    Encapsulates the print preview window and its properties.

    The PrintPreviewWinSettings object provides access to properties of the Print Preview window of the grid. Through this object, page headers, page footers, and other visual aspects can be set to the preview window. This object is accessed through the PreviewInfo property of the C1TrueDBGrid control.

    PrintInfo Encapsulates page setup and print job settings.
    The PrintInfo object is used to specify page layout and print job characteristics such as the name of the output device, margin settings, page headers and footers, and the number of copies to print.
    The PrintInfo property of a C1TrueDBGrid control returns the object that modifies the print job.
    The PrintInfo object is persistent, which means that a print layout can be defined at design time, and then recalled in code at run time.
    Split

    Represents a group of adjacent columns that scroll as a unit.

    TrueDBGrid for WinForms supports Excel-like splits that divide the grid into vertical and horizontal panes to provide users with different views of the data source. Each split is represented by a Split object and contains a group of adjacent columns that scroll as a unit.

    When a C1TrueDBGrid control is created, it contains one Split object by default. Many of the properties of the Split object also apply to the C1TrueDBGrid control as a whole, so there is no need to be concerned with splits until needed such as when creating fixed, non-scrolling columns. The object can be accessed as follows:

    To write code in Visual Basic

    VB
    Copy Code
    Me.C1TrueDBGrid1.Splits(0).Caption = "Split00"
    

    To write code in C#

    C#
    Copy Code
    this.c1TrueDBGrid1.Splits[0].Caption = "Split00";
    
    Style

    Encapsulates font, color, picture, and formatting information.

    Style objects encapsulate font, color, picture, and formatting information for a C1TrueDBGridC1TrueDBDropDownSplit, or C1DisplayColumn object. The Style object is a very flexible and powerful tool that provides Excel- and Word-like formatting capabilities for controlling the appearance of the grid's display.

    When a C1TrueDBGrid or C1TrueDBDropDown control is created, it contains ten built-in styles. Modify the built-in styles or add custom styles either in the designer or in code. Both controls also support several optional events that use Style objects to convey formatting information on a per-cell or per-row basis. The object can be accessed as follows:

    To write code in Visual Studio

    VB
    Copy Code
    Me.C1TrueDBGrid1.Styles("Normal").BackColor = System.Drawing.Color.Gray
    

    To write code in C#

    C#
    Copy Code
    this.c1TrueDBGrid1.Styles["Normal"].BackColor = System.Drawing.Color.Gray;
    
    ValueItems

    Encapsulates both the Values collection and ValueItem properties.

    The ValueItems object contains a collection and a couple of properties that can create alternate display values for database values in the grid. It can specify an allowable input value for a given C1DataColumn object, or it can also be used to translate raw data values into alternate text or graphics for display (for example, to display Balance Due and Paid in Full instead of the numeric data values 0 and 1). The ValueItems object contains display properties and a collection of ValueItem objects, the ValueItemCollection. This object can be accessed as follows:

    To write code in Visual Basic

    VB
    Copy Code
    Me.C1TrueDBGrid.Columns(0).ValueItems.MaxComboItems = 5
    

    To write code in C#

    C#
    Copy Code
    this.c1TrueDBGrid.Columns[0].ValueItems.MaxComboItems = 5;
    
    ValueItem The ValueItem object consists of two properties: DisplayValue and Value. The Value property specifies the underlying value in the database and the DisplayValue property specifies the value to be displayed in the grid. These objects are contained in the ValueItemCollection object, and can be edited in .NET's ValueItemCollection Editor. This editor is available in the C1TrueDBGrid Designer under the ValueItems object. For more information, see Using the ValueItemCollection Editor.
    VBar

    Represents the vertical scroll bar and its properties.

    The VBar object is used to specify properties of the vertical scrollbar. Through the use of the VScrollBar property, the developer can specify the width of the scroll bar, and whether is shows up automatically or not at all.