ComponentOne True DBGrid for WinForms
How to Use Splits / Creating and Removing Splits
In This Topic
    Creating and Removing Splits
    In This Topic

    In code, you must create and remove splits using the RemoveHorizontalSplit, InsertHorizontalSplit, RemoveVerticalSplit, and RemoveHorizontalSplit methods. Each method takes a zero-based split index:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim S As C1TrueDBGrid.Split
     
    ' Create a split with index 7.
    Me.C1TrueDBGrid1.InsertVerticalSplit(7) 
     
    ' Remove the split with index 5.
    Me.C1TrueDBGrid1.RemoveVerticalSplit(5)
    

    To write code in C#

    C#
    Copy Code
    C1TrueDBGrid.Split S;
     
    // Create a split with index 7.
    this.c1TrueDBGrid1.InsertVerticalSplit(7);
     
    // Remove the split with index 5.
    this.c1TrueDBGrid1.RemoveVerticalSplit(5);
    

    You can determine the number of splits in a grid using the SplitCollection Count property:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    ' Set variable equal to the number of splits in C1TrueDBGrid1.
    variable = Me.C1TrueDBGrid1.Splits.Count
    

    To write code in C#

    C#
    Copy Code
    // Set variable equal to the number of splits in C1TrueDBGrid1.
    variable = this.c1TrueDBGrid1.Splits.Count;
    

    You can iterate through all splits using the Count property, for example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    For n = 0 To Me.C1TrueDBGrid1.Splits.Count - 1
        Debug.WriteLine (Me.C1TrueDBGrid1.Splits(n).Caption)
    Next n
    

    To write code in C#

    C#
    Copy Code
    for (n = 0 ; n < this.c1TrueDBGrid1.Splits.Count; n++)
    {
        Console.WriteLine (this.c1TrueDBGrid1.Splits[n].Caption);
    }
    

    Of course, a more efficient way to code this would be to use a For Each...Next loop:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim S As C1TrueDBGrid.Split
    For Each S In Me.C1TrueDBGrid1.Splits
        Debug.WriteLine (S.Caption)
    Next
    

    To write code in C#

    C#
    Copy Code
    C1TrueDBGrid.Split S;
    foreach (S In this.c1TrueDBGrid1.Splits)
    {
        Console.WriteLine (S);
    }
    

    The new Split object will inherit all of its properties from the last object in the collection.

    See Also