ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Horizontal Scrolling and Fixed Columns

Scrolling is independent for each split. Often, one or more columns need to be prevented from scrolling horizontally or vertically so that the columns will always be in view. True DBGrid provides an easy way to keep any number of columns from scrolling at any location within the grid (even in the middle!) by setting a few split properties.

As an example, with a grid with three horizontal splits, the following code will "fix" columns 0 and 1 in the middle split:

·      Visual Basic

' Hide all columns in Splits(1) except for columns 0 and 1.

Dim Cols As C1TrueDBGrid.C1DisplayColumnCollection

Dim C As C1TrueDBGrid.C1DisplayColumn

 

Cols = Me.C1TrueDBGrid1.Splits(1).DisplayColumns

For Each C In Cols

    C.Visible = False

Next C

Cols(0).Visible = True

Cols(1).Visible = True

 

' Configure Splits(1) to display exactly two columns, and disable resizing.

With Me.C1TrueDBGrid1.Splits(1)

    .SplitSizeMode = SizeModeEnum.NumberOfColumns

    .SplitSize = 2

    .AllowHorizontalSizing = False

End With

·      C#

// Hide all columns in Splits[1] except for columns 0 and 1.

C1TrueDBGrid.C1DisplayColumnCollection Cols;

C1TrueDBGrid.C1DisplayColumn C;

 

Cols = this.C1TrueDBGrid1.Splits[1].DisplayColumns

foreach (C In Cols)

{

    C.Visible = false;

}

Cols(0).Visible = true;

Cols(1).Visible = true;

 

// Configure Splits[1] to display exactly two columns, and disable resizing.

C1TrueDBGrid1.Splits[1].SplitSizeMode = SizeModeEnum.NumberOfColumns;

C1TrueDBGrid1.Splits[1].SplitSize = 2;

C1TrueDBGrid1.Splits[1].AllowHorizontalSizing = false;

·      Delphi

var Cols: C1TrueDBGrid.C1DisplayColumnCollection;

 

// Hide all columns in Splits(1) except for columns 0 and 1.

Cols := Self.C1TrueDBGrid1.Splits[1].Columns;

for i := 0 to Cols.Count-1 do

  Cols[i].Visible := False;

Cols[0].Visible := True;

Cols[1].Visible := True;

 

// Configure Splits(1) to display exactly two columns, and disable resizing.

with Self.C1TrueDBGrid1.Splits[1] do

begin

  SplitSizeMode := SizeModeEnum.NumberOfColumns;

  SplitSize := 2;

  AllowHorizontalSplit := False;

end;

Usually, if columns 0 and 1 are kept from scrolling in one split, it will be desirable to have them invisible in the other splits:

·      Visual Basic

' Make columns 0 and 1 invisible in splits 0 and 2.

Dim Cols As C1TrueDBGrid.C1DisplayColumnCollection

Cols = Me.C1TrueDBGrid1.Splits(0).DisplayColumns

Cols(0).Visible = False

Cols(1).Visible = False

Cols = Me.C1TrueDBGrid1.Splits(2).DisplayColumns

Cols(0)Visible = False

Cols(1)Visible = False

·      C#

// Make columns 0 and 1 invisible in splits 0 and 2.

C1TrueDBGrid.C1DisplayColumnCollection Cols;

Cols = this.C1TrueDBGrid1.Splits[0].DisplayColumns;

Cols[0].Visible = false;

Cols[1].Visible = false;

Cols = this.C1TrueDBGrid1.Splits[2].DisplayColumns;

Cols[0]Visible = false;

Cols[1]Visible = false;

·      Delphi

// Make columns 0 and 1 invisible in splits 0 and 2.

var Cols: C1TrueDBGrid.C1DisplayColumnCollection;

 

Cols := Self.C1TrueDBGrid1.Splits[0].Columns;

Cols[0].Visible := False;

Cols[1].Visible := False;

Cols := Me.C1TrueDBGrid1.Splits[2].Columns;

Cols[0].Visible := False;

Cols[1].Visible := False;


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.