FlexGrid for WinForms | ComponentOne
C1.Win.C1FlexGrid Namespace / C1FlexGrid Class
Members Example

In This Topic
    C1FlexGrid Class
    In This Topic

    The C1FlexGrid control is a powerful, full-featured grid.

    C1FlexGrid provides advanced features such as outline trees, cell merging, masked editing, translated combo and image lists, owner-draw cells, and automatic data aggregation.

    Object Model
    C1FlexGrid ClassColumnCollection ClassColumn ClassComboBoxEditor ClassCellRange StructureFooters ClassGridGlyphs ClassCellRangeCollection ClassCellRange StructureGridPrinter ClassC1FlexGridRenderer ClassRowCollection ClassRow ClassCellRange StructureColumn ClassCellStyleCollection ClassCellStyle ClassGridTree Class
    Public Class C1FlexGrid 
       Inherits C1FlexGridBase
    public class C1FlexGrid : C1FlexGridBase 

    This class helps in enabling/disabling the following operations/behaviors for the FlexGrid control:

    Grid Operations:

    • FlexGrid can be used in bound mode, where it displays data from .NET data sources, or in unbound mode, where the grid itself manages the data. The data source for the grid using is set or retrieved using the DataSource property.
    • Enable/disable filtering, sorting on the grid using the AllowFilteringAllowSorting properties. The sort and filter operations in the grid can even be performed programmatically by using its Sort method and ApplyFilters method.
    • The current filter state can be saved or applied as an XML string using the FilterDefinition property.
    • Perform dynamic grouping on the grid using the GroupDescriptions property.
    • Get or set a custom comparer object used by the grid to perform grouping, merging, and searching operations using the CustomComparer property.
    • The drag/drop operation for the grid is defined by setting the DragMode and DropMode properties.
    • Determine whether the grid should move the cursor searching for entries as the user types using the AutoSearch property.  And, the search on the grid can even be applied programmatically by using the ApplySearch method.
    • The default glyphs used to display the icons such as the sort icon/filter icon can be replaced with custom icons by using the Glyphs property.
    • Specify the grid’s selection behavior by making use of the SelectionMode property. Further, the contents of the selected range can be retrieved or set using the Clip property.
    • Define the grid’s scrolling behavior using the ScrollOptions property.
    • Use the grid’s HitTest method for getting the information about the grid at a specified point on the grid’s surface.
    • The default appearance of any cell can be customized by handling the OwnerDrawCell event which only fires when the DrawMode property is set to DrawModeEnum.OwnerDraw.
    • It exposes a CreateImage method for creating an image of a portion of the grid or the entire grid.
    • FlexGrid can be saved to an excel file or loaded from an excel file by using the SaveExcel and LoadExcel methods.
    • Save/load the grid to/from xml files or print the grid with the help of the SaveGrid, LoadGrid, and PrintGrid methods.

    Row/Column Operations:

    • Retrieve the collection of Row and Column objects in the grid using the Rows and Cols property.
    • Specify whether the user is allowed to drag, freeze, and resize rows and columns with mouse using AllowDraggingAllowFreezing and AllowResizing properties respectively.
    • Auto size the rows/columns to fit their content by using the AutoSizeRows/AutoSizeCols methods.
    • Determine whether the grid should display a new row template after the last data row using the AllowAddNew property.
    • Add subtotal rows that contain aggregate data for the regular (non-subtotal) rows using the Subtotal method and to specify whether they should appear above or below the data using the SubtotalPosition property.
    • Retrieve all the zero-level Node rows on the grid using the Nodes property.

    Cell Operations:

    Keyboard Operations:

    • Allow deletion of rows using the DEL key with the help of AllowDelete property.
    • Specify whether the grid should handle the clipboard keys using the AutoClipboard property.
    • Define what action should be performed when the user presses the ENTER key/TAB key using the KeyActionEnter and KeyActionTab properties.

    Edit Operations:

    • Enable/disable editing on the grid using the AllowEditing property.
    • Use the ComboBoxEditor property to retrieve the ComboBoxEditor object that provides easy access to properties of the currently active ComboBox editor.
    • Get or set the reference to the cell editor that is currently active using the Editor property.

    This code example depicts how we can initialize the FlexGrid control in bound mode and display a tooltip for each cell:

    C1FlexGrid _flex;
    ToolTip _toolTip;
    private void Form1_Load(object sender, EventArgs e)
       //Initialize and bind the FlexGrid control           
       _flex = new C1FlexGrid();
       _flex.Location = new System.Drawing.Point(20, 80);
       _flex.Size = new System.Drawing.Size(800,500);
       _flex.DataSource = productsTable;            
       //Bind events to use a custom editor and display the tooltip 
       _flex.StartEdit += _flex_StartEdit;
       _flex.MouseMove += _flex_MouseMove;
       //Initialize the tooltip control used to display the tooltip for each cell
       _toolTip = new ToolTip();            
    private void _flex_MouseMove(object sender, MouseEventArgs e)
       //To show Tooltip when mouse is moved over the grid. Initialize and bind the FlexGrid control
       HitTestInfo hitTestInfo = _flex.HitTest(e.Location);            
       _toolTip.SetToolTip(_flex,String.Format("Mouse is over the ({0},{1}) cell \n Cell Type is : {2}", new object[] { hitTestInfo.Row, hitTestInfo.Column ,hitTestInfo.Type}));
    private void _flex_StartEdit(object sender, RowColEventArgs e)
       if (_flex.Cols[e.Col].Name == "UnitsInStock")
          //Setting the grid's Editor property
          _flex.Editor = new NumericUpDown();
    Inheritance Hierarchy


    See Also