FlexGrid for WinForms
Step 1 of 5: Create the Controls
Show AllShow All
Hide AllHide All

Start a new project and add two controls:

If you can't find the C1FlexGrid control in the Toolbox, right-click on the toolbox and select Choose Items. Then, look for the C1FlexGrid control on the list of .NET components and make sure it is checked. If you can't find the grid in the component list, you may need to re-install the product.

  1. Set the following properties in the Properties window:
    • Command Button
      Property Setting
      Dock Top
      Text "Open XML File…"
    • C1FlexGrid
      Property Setting
      Dock Fill
  2. Double-click the form caption area to open the code window. At the top of the file, add the following statement:

    To write code in Visual Basic

    To write code in C#

    This makes the objects defined in the C1FlexGrid assembly visible to the project and saves a lot of typing.

  3. Set up the grid either in the designer using the Properties window and editors, or in code by typing (or copying) the following code.

    In the Designer

    Set the following properties for the C1FlexGrid control in the Properties window:

    Property Setting
    Cols.Count 2
    Cols.Fixed 0
    ExtendLastCol True
    Rows.Count 1
    Tree.Column 0
    Tree.Style SimpleLeaf

    Set up the styles for the grid:

    • Open the C1FlexGrid Style Editor by selecting Styles from the C1FlexGrid Tasks menu. For more information on accessing the C1FlexGrid Style Editor, see Accessing the C1FlexGrid Style Editor.
    • Select Normal in the list of Built-In Styles.
    • Set the Border.Style property to None, the TextAlign property to LeftCenter, and the WordWrap property to False.
    • Click the Add button.
    • Rename CustomStyle1 to Data.
    • Set the BackColor property to Control.
    • Click OK to close the editor.

    Set up the columns for the grid:

    • Select Column 0 in the grid. This will open the Column Tasks menu for Column 0.
    • Set the Column Caption to Element.
    • Uncheck the Allow Editing check box.
    • Select Column 1.
    • Set the Column Caption to Text.

    Alternatively, the columns can also be set up through the C1FlexGrid Column Editor:

    • · Open the C1FlexGrid Column Editor by selecting Designer in the C1FlexGrid Tasks menu. For details on how to access the C1FlexGrid Column Editor, see Accessing the C1FlexGrid Column Editor.
    • Select Column 0 in the right pane.
    • In the left pane, set the AllowEditing property to False and the Caption property to Element.
    • Select Column 1 in the right pane.
    • In the left pane, set the Caption property to Text.
    • Click OK to close the editor.

    In Code

    To write code in Visual Basic

    To write code in C#

Run the program and observe the following:

The code starts by setting up the grid layout and column heading text.


Next, it initializes the outline tree using the Tree property and prevents editing of the XML nodes by setting the AllowEditing property of the first column to False. Note that the user can still edit data in the second column, which contains the data in each XML node.

Now the control is ready. We can start adding some code to it.

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback