>>Does anybody know how to lock a column in a grid control ? I have a grid with about 20 columns, and I always want the first 2 to be visible, regardless of the relativecolumn property.
>>
>>Any help would be much appreciated.
>>
>>Derek Chapman
>
>
>>****UT Search *****
>>>Is it possible to lock the first column of a grid so that it always stays visible while scrolling the remaining columns
>> left and right? I know this can be done in Excel, but I can't seem to find how to do it with a VFP grid.
>>
>> If you have time and patience, you can play with this two snippets:
>>
>> **** Grid.Scrolled event
>> LPARAMETERS nDirection
>> if thisform.blockscroll=.t.
>> return
>> endif
>> thisform.blockscroll=.t.
>> do case
>> case this.column1.columnorder=this.leftcolumn
>> case this.column1.columnorder<=this.leftcolumn-1
>> *for n=this.column1.columnorder+1 to this.leftcolumn-1
>for n=this.column1.columnorder to this.leftcolumn
>> this.column1.columnorder=n
>> endfor
>> *this.doscroll(4)
>> this.refresh
>> case this.column1.columnorder>this.leftcolumn
>> for n=this.column1.columnorder-1 to this.leftcolumn step -1
>> this.column1.columnorder=n
>> endfor
>> this.column1.setfocus
>> endcase
>> thisform.blockscroll=.f.
>> *** Grid.afterrowcolchange event
>> this.scrolled
>
>I believe this is originally Edward Pikman's code.
I had used this code in my project, but user complain that if the some middle Column is very width, need half or more than half of grid width,
the final screen may not work as they wish!
I would suggest Derek to use two grids instead,
leftgrid has only two fixed column, and the left 18 columns are put in rightgrid
the only thing you need to do is:
LPARAMETERS nKeyCode, nShiftAltCtrl
DO CASE
CASE THISFORM.ACTIVECONTROL.NAME = THISFORM.LEFTGRID.NAME
DO CASE
CASE nKeyCode = 9
IF THISFORM.LEFTGRID.ACTIVECOLUMN = THISFORM.LEFTGRID.COLUMNCOUNT
NODEFAULT
THISFORM.RIGHTGRID.COLUMN1.SETFOCUS
ENDIF
CASE nKeyCode = 15 or nKeycode = -400
IF THISFORM.LEFTGRID.ACTIVECOLUMN = 1
NODEFAULT
FocusMacro = "THISFORM.RIGHTGRID.COLUMN" + ;
ALLTRIM(STR(THISFORM.RIGHTGRID.COLUMNCOUNT)) + ;
".SETFOCUS "
&FocusMacro
ENDIF
ENDCASE
CASE THISFORM.ACTIVECONTROL.NAME = THISFORM.RIGHTGRID.NAME
DO CASE
CASE nKeyCode = 9
IF THISFORM.RIGHTGRID.ACTIVECOLUMN = THISFORM.RIGHTGRID.COLUMNCOUNT
NODEFAULT
THISFORM.LEFTGRID.COLUMN1.SETFOCUS
ENDIF
CASE nKeyCode = 15 or nKeycode = -400
IF THISFORM.RIGHTTGRID.ACTIVECOLUMN = 1
NODEFAULT
FocusMacro = "THISFORM.LEFTGRID.COLUMN" + ;
ALLTRIM(STR(THISFORM.LEFTGRID.COLUMNCOUNT)) + ;
".SETFOCUS "
&FocusMacro
ENDIF
ENDCASE
ENDCASE
Then, it will be a perfect part if someone can write a line shape object in middle of two grid and try to move the column from left grid to right grid or
from right grid to left grid!
But I think it need more ppl to think... Too hard to do for me! ~_~'
Currently, I have made a Line which can drag-drop to handle up-down two grid height and make a min. height for each grid!
I think the migration of column within two grid is possible to do!
For add a column, just change the columncount +1 and copy another grid
first column information to last column!
For Delete a Column, move the Column.ColumnOrder to ColumnCount and
change the COlumnCount -1....
But the most hard part is:
how to decide a column is put to left or put to right!
Maybe change the Spec. to:
Click on Line is migrate 1 column to leftgrid
RightClick on line is migrate back!but I donno how to make a correct grid.width
p.s. My Coding Technique is so poor! Hope some expertise can do! ^-^;
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.