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.
Property | Setting |
---|---|
Dock | Top |
Text | "Open XML File…" |
Property | Setting |
---|---|
Dock | Fill |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Imports C1.Win.C1FlexGrid |
To write code in C#
C# |
Copy Code
|
---|---|
using C1.Win.C1FlexGrid; |
This makes the objects defined in the C1FlexGrid assembly visible to the project and saves a lot of typing.
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:
Set up the columns for the grid:
Alternatively, the columns can also be set up through the C1FlexGrid Column Editor:
In Code
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Initialize the grid. C1FlexGrid1.Rows.Count = 1 C1FlexGrid1.Cols.Count = 2 C1FlexGrid1.Cols.Fixed = 0 C1FlexGrid1.ExtendLastCol = True C1FlexGrid1(0, 0) = "Element" C1FlexGrid1(0, 1) = "Text" ' Initialize the outline tree. C1FlexGrid1.Tree.Column = 0 C1FlexGrid1.Tree.Style = TreeStyleFlags.SimpleLeaf C1FlexGrid1.Cols(0).AllowEditing = False ' Initialize styles. C1FlexGrid1.Styles.Normal.Border.Style = BorderStyleEnum.None C1FlexGrid1.Styles.Normal.TextAlign = TextAlignEnum.LeftCenter C1FlexGrid1.Styles.Normal.WordWrap = False Dim cs As CellStyle = C1FlexGrid1.Styles.Add("Data") cs.BackColor = SystemColors.Control End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void Form1_Load( System.object sender, System.EventArgs e) { // Initialize the grid. c1FlexGrid1.Rows.Count = 1; c1FlexGrid1.Cols.Count = 2; c1FlexGrid1.Cols.Fixed = 0; c1FlexGrid1.ExtendLastCol = true; c1FlexGrid1[0, 0] = "Element"; c1FlexGrid1[0, 1] = "Text"; // Initialize the outline tree. c1FlexGrid1.Tree.Column = 0; c1FlexGrid1.Tree.Style = TreeStyleFlags.SimpleLeaf; c1FlexGrid1.Cols[0].AllowEditing = false; // Initialize styles. c1FlexGrid1.Styles.Normal.Border.Style = BorderStyleEnum.None; c1FlexGrid1.Styles.Normal.TextAlign = TextAlignEnum.LeftCenter; c1FlexGrid1.Styles.Normal.WordWrap = false; CellStyle cs = c1FlexGrid1.Styles.Add("Data"); cs.BackColor = SystemColors.Control;} |
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.