Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Freeze panes in standard grid control

Freeze panes in standard grid control

Freeze panes in standard grid control


I'm trying to replicate the 'freeze panes' feature available on Microsoft Excel for a standard foxpro grid control.

Unfortunately, the only way I can see to do this is to use the 'split', or 'partition' properties.  Now, the problem with this solution is that all of the columns are still available to see in both panels, I do not want the columns in the left panel visible in the right panel and vice versa.

Has anybody got any ideas???



RE: Freeze panes in standard grid control

I'm confused, you say you want it to work like Excel, and in Excel I can "see" the other rows and columns from the "Frozen" panes (it just takes an extra step) - how is it different?

The VFP native grid is not a speadsheet - if you want a speadsheet, there are 3rd party controls - including Excel - consider using them.


RE: Freeze panes in standard grid control

why not set the visible property of the column to .f.

Attitude is Everything

RE: Freeze panes in standard grid control

rgbean, I think that you are actually splitting the panes, like the grid control does, by using the split bar at the top right of the sheet?  If you move to cell A18, and choose 'freeze panes' from the window menu, then you will see what I mean!!

I know that the grid control is not a spread sheet, I just want to keep some fields visible, without the user having the option to scroll in both panes, hence, 'freezing' the fields in question.

danceman - i thought of that option, but the column that I want to appear in pane 0, and not in pane 1, disappears from both panes if I do this, you can 'unlink' the panes for certain properties, but unfortunately control sources is not one of them.

I have tried changing the control source of the relative column 1 to my required field,but this makes the grid flick about a bit, as I have to set the focus to column one in order to discover what the actual visible left hand column is.

I think a third party control is the answer - maybe one of the data access controls that come with Visual Basic....



RE: Freeze panes in standard grid control

Try this:
How to freeze (lock) a column in the grid without use of split bar

The approach is based on a simple principle. LeftColumn property of the grid represents a column that is currently the leftmost visible column in the grid with current horizontal scrolling. As we scroll the grid horizontally, this property changes. We can assign this number to the ColumnOrder property of the column we want to hold and that’s all:

this.Columns(1).ColumnOrder = this.LeftColumn

You can use this in the Scrolled and AfterRowColChange events of the grid. However, there is a little problem with this: order of columns spoiled after few scrolling forward and back. This is because column order changes using principle "replace older column by newer on that place", so older column is placed on place of newer column. Column orders of all other columns are not changed. This causes the problem. This FAQ describes an approach that allows to organize freezing of the column and workaround most issues.

The code is a very basic and simple to give the basics of the approach. Code samples could be improved to work correctly in case user change order of columns, as well as improve the logic related to the focus change.
Following is a code that updates columns in grid to make first column always leftmost. Use it in the Scrolled event when grid is scrolled horizontally and in the AfterRowColChange event when active column is changed in the grid.

    local i
    if this.columns(1).ColumnOrder < this.LeftColumn
        && we scroll forward
        for i=this.columns(1).ColumnOrder to this.LeftColumn-1
            this.columns(1).ColumnOrder = this.columns(1).ColumnOrder + 1
        && we scroll backward
        for i=this.LeftColumn+1 to this.columns(1).ColumnOrder
            this.columns(1).ColumnOrder = this.columns(1).ColumnOrder - 1


RE: Freeze panes in standard grid control

Hey!  This looks like the stuff I have been looking for!  

I'll let you know how I get on - thanks very much!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close