Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 To: piyush Vaishnawswami
  Where is piyush Vaishnawswami?
 Rajkot
 India
 piyush Vaishnawswami
 Tags
Subject: RE: Grid Grouoing
Thread ID: 268947 Message ID: 269001 # Views: 65 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: Grids
Date: Thursday, July 15, 2010 11:57:28 PM         
   


> Hello expert,
>
> how to display group total in vfp grid.
>
>
>
> it is possible?
>
> Piyush
try this sample for totalizing rows/columns in grid (change values and see the interactive total in row and colums).
Adapt to your case.

*-- Author Yousfi Benameur EL BAYADH ALGERIA
*-- Time Stamp:   01/13/09 10:56:09 PM
*Réalise la sommation des chps num sur les lignes et colonnes+interactif avec AfterRowColChange.
*colorise le résultat dex totaux

CREATE CURSOR YTOTAUX (DESIGN C(20),s1 n(10,2),s2 n(10,2),s3 n(10,2),s4 n(10,2),s5 n(10,2),s6 n(10,2),s7 n(10,2),s8 n(10,2),s9 n(10,2),s10 n(10,2),total_l n(10,2))
INSERT INTO ytotaux VALUES ("AAAAAAAAAAAAA",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("BBBBBBBBBBBBB",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("CCCCCCCCCCCCC",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("DDDDDDDDDDDDD",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("EEEEEEEEEEEEE",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("FFFFFFFFFFFFF",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("GGGGGGGGGGGGG",10,10,10,10,10,10,10,10,10,10,0)
INSERT INTO ytotaux VALUES ("HHHHHHHHHHHHH",10,10,10,10,10,10,10,10,10,10,0)

yform=createObject('asup')
yform.show
read events
return

DEFINE CLASS asup AS form
	Top = 0
	Left = 0
	Height = 313
	Width = 770
	DoCreate = .T.
        borderstyle=2
        maxbutton=.f.
	autocenter=.t.
	showWindow=2
	Caption = "Grid with total lines/columns"
	Name = "Form1"

	ADD OBJECT grid1 AS grid WITH ;
		Height = 265, ;
		Left = 0, ;
		Top = 1, ;
		Width = 804, ;
		Name = "Grid1"

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 276, ;
		Left = 250, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Calculate", ;
		Name = "Command1"

ADD OBJECT label1 AS label WITH ;
		Top = 276, ;
		Left = 355, ;
		Height = 27, ;
		Width = 150, ;
		backstyle=0, ;
		autosize=.t., ;
		Caption = "If the row [TOTAL_C] dont exists it added-Calculations are interactivechange.", ;
		Name = "Label1"

	PROCEDURE Load
		SELE YTOTAUX
		go botto
		xdesign=design
		if xdesign#"TOTAL_C"
		APPE BLAN
		repl  design with "TOTAL_C"
		endi
		repl all total_l with 0

		go botto

		for i=2 to fcount()
		if type(field(i))="N"
		repl (field(i)) with 0 
		endi 
		endfor
		go top
	ENDPROC

	PROCEDURE command1.Click
		&&total columns
		sele ytotaux
		rec=recno()
		go botto

		for i=2 to fcount()
		if type(field(i))="N"
		repl (field(i)) with 0 
		endi 
		endfor
	
		for i=2 to fcount()
		sum evaluate(field(i)) to x for type(field(i))="N"
		go botto
		repl (field(i)) with x     
		endfor
		
		thisform.grid1.refresh
		
		&&total lines
		sele ytotaux
		go top
		
		scan
		xtotal_L=0
		for i=1 to fcount()-1
		if type(field(i) )="N"
		xtotal_L=xtotal_L+evaluate(field(i))
		endi
		endfor
		repl total_l with xtotal_l
		endscan
		go rec		
		thisform.grid1.refresh
		
		&&colors
		with thisform.grid1
		  .setAll("dynamicBackcolor","iif(recno()=reccount(),rgb(0,255,0),rgb(255,255,255))","column")
		.column12.dynamicbackcolor="rgb(255,0,0)"
		endwith
		thisform.grid1.refresh
		
	ENDPROC
	
	PROCEDURE grid1.AfterRowColchange()
	LPARAMETERS nColIndex
	thisform.command1.click()
	ENDPROC
	
	Procedure destroy
	clea events
	ENDPROC

ENDDEFINE
*



Regards
Yousfi Benameur

ENTIRE THREAD

Grid Grouoing Posted by piyuhsh vaishnavswami @ 7/15/2010 3:31:42 PM
RE: Grid Grouoing Posted by Rahul Maudgill @ 7/15/2010 3:47:51 PM
RE: Grid Grouoing Posted by tushar @ 7/15/2010 3:58:28 PM
RE: Grid Grouoing Posted by piyuhsh vaishnavswami @ 7/15/2010 9:24:54 PM
RE: Grid Grouoing Posted by Yousfi Benameur @ 7/15/2010 11:57:28 PM
RE: Grid Grouoing Posted by Anders Altberg @ 7/16/2010 12:25:31 AM
RE: Grid Grouoing Posted by Christian Tabligan @ 7/16/2010 2:14:21 AM
RE: Grid Grouoing Posted by mk sharma @ 7/17/2010 9:08:20 AM
RE: Grid Grouoing Posted by piyuhsh vaishnavswami @ 7/18/2010 11:32:02 AM
RE: Grid Grouoing Posted by Anders Altberg @ 7/18/2010 11:59:07 AM
RE: Grid Grouoing Posted by Christian Tabligan @ 7/19/2010 6:36:06 AM