Visual Basic Code of the Week (COTW)
Issue #92
Online Version at (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp. Word, Excel and Visual Basic are trademarks of Microsoft Corp. True DBGrid is copyright by Apex Software Corporation.

Consulting Services

We are offering our consulting services for all types of projects related to Visual Basic, Outlook, Exchange Server and other Microsoft environments. If you are looking for a high-quality company to provide outstanding consulting services to your organization, email us at


In this Issue

This issue shows how to "freeze" columns at the leftmost portion of a grid.


There are two routines in this module. One to freeze columns and one to unfreeze the columns. They are very useful if you have many columns in your grid and need to keep a few important fields visible at all times. A good example of this would be an employee listing where you have columns such as name, address, salary, department, phone number, cell phone number and other fields in a grid. You would probably want to freeze the Name column so when you scroll through the additonal fields you will always know who the data is for based on the "frozen" column at the left.

An interesting enhancement to this routine would be the option to specify the field names to freeze instead of just freezing the leftmost columns.


Public Sub FreezeColumnsOnLeft(grd As TDBGrid, lHowManyColumns As Long)

Performs the work necessary to freeze the number of columns specified in lHowManyColumns on the left side of the grid. You need to pass the grid you want to modify as the first parameter and the number of columns to freeze as the second parameter.

Public Sub UnfreezeColumnsOnLeft(grd As TDBGrid)

This routine performs the opposite function of FreezeColumnsOnLeft. It assumes you have previously called FreezeColumnsOnLeft. If you haven't and you have not defined additional splits nothing will happen. If you have defined additional splits they will be removed since this function just removes the leftmost split.

Sample Usage

This source code will freeze the left 2 columns of data in a grid called TDBGrid1. It will then unfreeze the 2 columns and then freeze the three left most columns of data.

    FreezeColumnsOnLeft TDBGrid1, 2
    UnfreezeColumnsOnLeft TDBGrid1
    FreezeColumnsOnLeft TDBGrid1, 3

Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address:

This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945