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.
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; |
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.
To use the FixColumn method to fix columns, follow the steps below:
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); |
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); |
This concludes the tutorial.