Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freeze panes in standard grid control 1

Status
Not open for further replies.

fruityBoy

Programmer
Jul 21, 2000
51
GB
Hi

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???

Thanks

Simon
 
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.

Rick
 
why not set the visible property of the column to .f. Attitude is Everything
 
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....

Thanks

Simon
 
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.

Description

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.
Code:
	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
		endfor
	else
		&& we scroll backward
		for i=this.LeftColumn+1 to this.columns(1).ColumnOrder
			this.columns(1).ColumnOrder = this.columns(1).ColumnOrder - 1
		endfor
	endif

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

I'll let you know how I get on - thanks very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top