Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP 6.0 Grids
Message
From
29/06/2001 13:17:51
Gerry Schmitz
GHS Automation Inc.
Calgary, Alberta, Canada
 
 
To
29/06/2001 02:13:36
Henry Ravichander
RC Management Systems Inc.
Saskatchewan, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00524840
Message ID:
00525260
Views:
19
>Can each column in a grid have a separate control source.

You mean "different" ? Yes.

>> I have the UI set up with a combo box and a grid with 8 columns. Headers for cols 2-8 have the date of any given month displayed as chatacters using the dtoc function. is there a way to loop and insert appropriate values in the cells in teh grid. <<

Well, you don't really "insert" values into the cells in a grid ... you program the Grid in such a way that it "knows" what to display in a cell.

Even if you could "insert" values (into columns), you could only do this for a single row; after that, all rows would have the same values. This is because, when a grid "display itself", it evaluates every .ControlSource, for every column, relative to an applicable row/record in an associated table. "Inserting values" would be the same as applying "constants" to all rows.

A picture is worth a thousand words, or a program ... try this to see what I mean:
   CREATE CURSOR DB_TMP ( ;
      FIELD1   C( 04 ), ;
      FIELD2   C( 04 ) )

   INSERT INTO DB_TMP VALUES ( "0001", "AAAA" )
   INSERT INTO DB_TMP VALUES ( "0002", "BBBB" )
   INSERT INTO DB_TMP VALUES ( "0003", "BBBB" )
   INSERT INTO DB_TMP VALUES ( "0004", "BBBB" )

   SELECT DB_TMP
   GO TOP

   m.LO_Form = CREATEOBJECT( "Form" )

   m.LO_Form.AddObject( "Grid1", "Grid_Base" )

   WITH m.LO_Form.Grid1
      .Width   = m.LO_Form.Width
      .Height  = m.LO_Form.Height
      .Visible = .T.
   ENDWITH

   m.LO_Form.Show()

   ON KEY LABEL ESC CLEAR EVENTS
   READ EVENTS
   ON KEY LABEL ESC CLEAR EVENTS

   CLEAR ALL

PROCEDURE My_Function
   PARAMETER TC_Day

   RETURN STR( RECNO( "DB_TMP" ) * VAL( m.TC_Day ) )

DEFINE CLASS Grid_Base AS Grid
   ReadOnly = .T.
   RecordSource = "DB_TMP"

   ADD OBJECT Column1 AS Grid_Column WITH ;
      Header1.Caption = "F1", ;
      ControlSource = "FIELD1"

   ADD OBJECT Column2 AS Grid_Column WITH ;
      Header1.Caption = "F2", ;
      ControlSource = "FIELD2"

   ADD OBJECT Column3 AS Grid_Column WITH ;
      Header1.Caption = "Day 1", ;
      ControlSource = "My_Function( '1' )"

   ADD OBJECT Column4 AS Grid_Column WITH ;
      Header1.Caption = "Day 2", ;
      ControlSource = "My_Function( '2' )"

ENDDEFINE

DEFINE CLASS Grid_Column AS Column
   ADD OBJECT Header1  AS Grid_Header
   ADD OBJECT TextBox1 AS Grid_TextBox
ENDDEFINE

DEFINE CLASS Grid_Header AS Header
ENDDEFINE

DEFINE CLASS Grid_TextBox AS TextBox
   BorderStyle = 0
   Margin = 0
ENDDEFINE
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform