Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to lock a grid column
Message
From
22/10/1999 16:51:26
 
 
To
21/10/1999 17:22:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00279660
Message ID:
00280266
Views:
18
Hi Larry.

>I can split a grid, but it doesn't work quite the way I want. Each pane contain the same fields; what I want is for the left pane to have the name field, the right pane to have the rest of the fields.

In the July 97 issue of FoxTalk, I had an article that described a drill-down grid (like a TreeView control, but a grid showing data). This grid has the behavior you're describing: a locked column. Actually, it supports locking a number of leftmost columns, not just the first one; in fact, the article specifically locks the first two columns. You'll have to adjust this code for a single column.

It's not easy, but here are the details for the grid class:

- Set the Partition property to an approximate value; it will be set at runtime to the proper value.

- Init() sets the left panel to not have a scroll bar. This can't be done at design time, so the grid will appear to have two vertical scroll bars. At runtime, however, this code eliminates the scroll bar for the left panel, making the grid look more like an Excel spreadsheet with a frozen panel. Init() also adjusts the partition position so the left panel just includes the first two columns:
with This
  .PanelLink  = .F.
  .Panel      = 0
  .ScrollBars = 1
  .Panel      = 1
  .PanelLink  = .T.
  .Partition  = .Column1.Width + .Column2.Width + 2
endwith
- Scrolled(), which is fired whenever the user scrolls the grid, ensures the appropriate columns are displayed in the appropriate panel by forcing the grid to scroll unwanted columns out of view if necessary.
LPARAMETERS nDirection
local lnI
Thisform.LockScreen = .T.
with This
  do case

* If either of the first two columns is visible in the
* right panel, scroll until they're no longer there.

    case .Panel = 1 and .LeftColumn <= 3
      for lnI = .LeftColumn to 2
        .DoScroll(5)
      next lnI

* If any column but the first two is visible in the left
* panel, scroll until they're no longer there.

    case .Panel = 0 and .LeftColumn > 1
      for lnI = .LeftColumn to 2 step - 1
        .DoScroll(4)
      next lnI
  endcase
endwith
Thisform.LockScreen = .F.
- Column1.Text1.GotFocus() ensures the right panel doesn't show the first two columns by setting focus to column 3 (the first column in the right panel) if necessary. This makes the grid act more like a spreadsheet.
with This.Parent.Parent
  if .Partition &lt;> 0 and .Panel = 1
    Thisform.LockScreen = .T.
    .Column3.SetFocus()
    if .LeftColumn &lt;> 3
      .DoScroll(5)
    endif .LeftColumn &lt;> 3
    Thisform.LockScreen = .F.
  endif .Partition &lt;> 0 ...
endwith
- Column1.Text1.LostFocus() moves to the third column (the first column we want displayed in the right panel). This makes the grid act more like a spreadsheet.
with This.Parent.Parent
  if .Partition &lt;> 0 and .Panel = 0
    .Panel = 1
    .Column3.SetFocus()
  endif .Partition &lt;> 0 ...
endwith
- Column2.Text1.When() prevents focus from being set to the Name column:
return .F.
- The columns in the right panel (column 3 and higher) contain a textbox class with the following When code to prevents the textbox from receiving focus if there isn't a partition or if focus is in the left panel:
with This.Parent.Parent
  return .Partition = 0 or .Panel = 1
endwith
Kind of ugly, but it works :)

Doug
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform