Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Locking columns in a grid control
Message
From
21/10/1998 22:09:33
 
 
To
21/10/1998 16:02:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00148979
Message ID:
00149207
Views:
14
>>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:
* ThisFOrm.Keypress()
* remember to set the Thisform.keypreview to .T.

LPARAMETERS nKeyCode, nShiftAltCtrl

DO CASE
CASE THISFORM.ACTIVECONTROL.NAME = THISFORM.LEFTGRID.NAME && at left grid
  DO CASE
  CASE nKeyCode = 9  && Press Tab to next Column!
  IF THISFORM.LEFTGRID.ACTIVECOLUMN = THISFORM.LEFTGRID.COLUMNCOUNT && END COL.
    NODEFAULT  && SKIP BACKWARD TO FIRST COLUMN
    THISFORM.RIGHTGRID.COLUMN1.SETFOCUS && Jump Focus to right Column
  ENDIF
  CASE nKeyCode = 15 or nKeycode = -400  
     * Runtime Shift+tab Code and Develop Time are different!
  IF THISFORM.LEFTGRID.ACTIVECOLUMN = 1 && First COL.
    NODEFAULT  && SKIP BACKWARD TO FIRST COLUMN
    FocusMacro = "THISFORM.RIGHTGRID.COLUMN" + ;
                 ALLTRIM(STR(THISFORM.RIGHTGRID.COLUMNCOUNT)) + ;
                 ".SETFOCUS "
    &FocusMacro   && Focus at last column in Right grid!
  ENDIF
  ENDCASE
CASE THISFORM.ACTIVECONTROL.NAME = THISFORM.RIGHTGRID.NAME && at right grid
  DO CASE
  CASE nKeyCode = 9  && Press Tab to next Column!
  IF THISFORM.RIGHTGRID.ACTIVECOLUMN = THISFORM.RIGHTGRID.COLUMNCOUNT
    NODEFAULT  && SKIP BACKWARD TO FIRST COLUMN
    THISFORM.LEFTGRID.COLUMN1.SETFOCUS && Jump Focus to right Column
  ENDIF
  CASE nKeyCode = 15 or nKeycode = -400  
     * Runtime Shift+tab Code and Develop Time are different!
  IF THISFORM.RIGHTTGRID.ACTIVECOLUMN = 1 && First COL.
    NODEFAULT  && SKIP BACKWARD TO FIRST COLUMN
    FocusMacro = "THISFORM.LEFTGRID.COLUMN" + ;
                 ALLTRIM(STR(THISFORM.LEFTGRID.COLUMNCOUNT)) + ;
                 ".SETFOCUS "
    &FocusMacro   && Focus at last column in Left grid!
  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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform