Pin columns to the left or right edges of the grid for easy reference while scrolling
Locked columns remain visible at fixed positions while other columns scroll horizontally. This is useful for keeping key identifier columns (like names or IDs) always visible, or for pinning action columns to the right edge.
// Lock column to the left edgeTeeGrid1.Columns['ID'].Locked := TColumnLocked.Left;// Lock column to the right edge TeeGrid1.Columns['Actions'].Locked := TColumnLocked.Right;// Unlock column (default)TeeGrid1.Columns['Name'].Locked := TColumnLocked.None;
// Lock the first column to the leftTeeGrid1.Columns[0].Locked := TColumnLocked.Left;// Lock the last column to the rightTeeGrid1.Columns[TeeGrid1.Columns.Count - 1].Locked := TColumnLocked.Right;
// Lock multiple columns to the leftTeeGrid1.Columns['ID'].Locked := TColumnLocked.Left;TeeGrid1.Columns['Name'].Locked := TColumnLocked.Left;// These columns stay visible on the left while others scroll
Add visual separators between locked and scrollable columns:
procedure TForm1.AddLockedColumnBorders;var I: Integer; Column: TColumn;begin for I := 0 to TeeGrid1.Columns.Count - 1 do begin Column := TeeGrid1.Columns[I]; if Column.Locked = TColumnLocked.Left then begin // Add right border to left-locked columns Column.Format.Stroke.Visible := True; Column.Format.Stroke.Color := TColors.DkGray; Column.Format.Stroke.Size := 2; end else if Column.Locked = TColumnLocked.Right then begin // Add left border to right-locked columns Column.Format.Stroke.Visible := True; Column.Format.Stroke.Color := TColors.DkGray; Column.Format.Stroke.Size := 2; end; end;end;
// Check if grid has any locked columnsfunction HasLockedColumns: Boolean;var I: Integer;begin Result := False; for I := 0 to TeeGrid1.Columns.Count - 1 do begin if TeeGrid1.Columns[I].Locked <> TColumnLocked.None then begin Result := True; Exit; end; end;end;// Count locked columns by typefunction CountLockedColumns(const LockType: TColumnLocked): Integer;var I: Integer;begin Result := 0; for I := 0 to TeeGrid1.Columns.Count - 1 do if TeeGrid1.Columns[I].Locked = LockType then Inc(Result);end;// Usagevar LeftCount, RightCount: Integer;begin LeftCount := CountLockedColumns(TColumnLocked.Left); RightCount := CountLockedColumns(TColumnLocked.Right); ShowMessage(Format('Locked: %d left, %d right', [LeftCount, RightCount]));end;
Lock key identifier columns — Lock columns containing IDs, names, or other key identifiers to the left so users can always see what row they’re looking at.
Lock action columns to the right — Columns with buttons, checkboxes, or action icons work well locked to the right edge.
Provide visual distinction — Use different background colors or borders to help users distinguish locked columns from scrollable ones.
Save user preferences — If users can lock/unlock columns, save their preferences and restore them on application startup.