ComponentOne List for WinForms
In This Topic
    Tutorial 12 - Creating Fixed, Nonscrolling Columns in List
    In This Topic

    Often, you would like to prevent one or more columns from scrolling horizontally or vertically so that they will always be in view. The SplitCollection of List for WinForms provides a generalized mechanism for defining groups of adjacent columns, and can be used to implement any number of fixed, nonscrolling columns or rows. In this tutorial, you will learn how to write code to create a list with two horizontal splits, and then "fix" a pair of columns in the leftmost split.

    1. Follow steps 1 through 4 of Tutorial 1 - Binding C1List to a DataSet to create a project with a C1List bound to a Data Set.
    2. In the Form_Load event, add the following code to create an additional split and to fix columns 0 and 1 in the leftmost split:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' Hide all the columns from the left split except col 0 and 1.
      Dim i As Integer
      For i = 2 To Me.C1List1.Columns.Count - 1
          Me.C1List1.Splits(0).DisplayColumns(i).Visible = False
      Next i
      
      ' Configure the left split to display 2 columns exactly.
      Me.C1List1.Splits(0).SplitSizeMode = C1.Win.C1List.SizeModeEnum.NumberOfColumns
      Me.C1List1.Splits(0).SplitSize = 2
      Me.C1List1.Splits(0).AllowHorizontalSizing = False
      
      ' Make col 0 and 1 invisible in the right split. 
      Me.C1List1.Splits(1).DisplayColumns(0).Visible = False
      Me.C1List1.Splits(1).DisplayColumns(1).Visible = False
      

      To write code in C#

      C#
      Copy Code
      // Hide all the columns from the left split except col 0 and 1.
      int i; 
      for ( i = 2; i<= this.C1List1.Columns.Count - 1; i++)   
      {   
          this.c1List1.Splits[0].DisplayColumns[i].Visible = false;   
      }
          
      // Configure the left split to display 2 columns exactly.   
      this.c1List1.Splits[0].SplitSizeMode = C1.Win.C1List.SizeModeEnum.NumberOfColumns;   
      this.c1List1.Splits[0].SplitSize = 2;   
      this.c1List1.Splits[0].AllowHorizontalSizing = false;
      
      // Make col 0 and 1 invisible in the right split.    
      this.c1List1.Splits[1].DisplayColumns[0].Visible = false;    
      this.c1List1.Splits[1].DisplayColumns[1].Visible = false;
      

      Run the program and observe the following:

      The two columns (Birth and Country) in the leftmost split are fixed and cannot be scrolled. In fact, there is no horizontal scroll bar present under the left split. A horizontal scroll bar appears under the rightmost split, allowing users to scroll the columns in this split.

      You can use splits to create fixed, nonscrolling columns anywhere within the list even in the middle. You can also use splits to present different views of your data. For example, you can create splits which scroll independently (in the vertical direction) so that users may compare records at the beginning of the database with those at the end. For more information, see How to Use Splits.

      Note: There is another way to fix columns. Use the FixColumn method for the DisplayColumn object.

      To use the FixColumn method to fix columns, follow the steps below:

    3. Add another C1List control (C1List2) to the form right below C1List1. Add two buttons with the text "Fix Columns" and "Unfix Columns", respectively.
    4. Under the Button_Click1 event for Fix Columns, add the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' Make the country and birth columns fixed.   
      Me.C1List2.Splits(0).DisplayColumns("Birth").FixColumn(True)   
      Me.C1List2.Splits(0).DisplayColumns("Country").FixColumn(True, 1)
      

      To write code in C#

      C#
      Copy Code
      // Make the country and birth columns fixed.   
      this.c1List2.Splits[0].DisplayColumns["Birth"].FixColumn(true);   
      this.c1List2.Splits[0].DisplayColumns["Country"].FixColumn(true, 1);
      
    5. Under the Button_Click2 event for Unfix Columns, add the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' Make the country and birth columns unfixed.   
      Me.C1List2.Splits(0).DisplayColumns("Country").FixColumn(False, 1)   
      Me.C1List2.Splits(0).DisplayColumns("Birth").FixColumn(False, 0)
      

      To write code in C#

      C#
      Copy Code
      // Make the country and birth columns unfixed.   
      this.c1List2.Splits[0].DisplayColumns["Country"].FixColumn(false, 1);   
      this.c1List2.Splits[0].DisplayColumns["Birth"].FixColumn(false, 0);
      
    6. Run the program and click Fix Columns. The first two columns are fixed and you cannot scroll them. Click Unfix Columns. The first two columns are not fixed. You may fix any column this way.

    This concludes the tutorial.