Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate column on grid
Message
From
31/01/2024 07:39:14
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
To
25/01/2024 18:12:07
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01687576
Message ID:
01687608
Views:
84
Hello community,

i created these bindevents for columns 1,5,8,9 so that when i change the value of any of them the procedure can calculate the value of my column13.
but it doesn't work!

As I'm already getting a headache, can someone help me explain what's wrong and possibly correct the code?

Here is the code:
PUBLIC oManipulador as Manipulador

*!* - Instancia o objeto manipulador
oManipulador = CREATEOBJECT("Manipulador")


loGrid = SFT.PAGEFRAME1.PAGE1.CONT1.GRID1
  
* Set the ControlSource for each column
*loGrid.Column1.ControlSource = "FI.ALTURA"
*loGrid.Column5.ControlSource = "FI.ESPESSURA"
*loGrid.Column8.ControlSource = "FI.LARGURA"
*loGrid.Column9.ControlSource = "FI.PARTES"


* Bind the event to Column1
BINDEVENT(loGrid.Column1, "AfterRowColChange", oManipulador, "CalculateTotal")

* Bind the event to Column5
BINDEVENT(loGrid.Column5, "AfterRowColChange", oManipulador, "CalculateTotal")

* Bind the event to Column8
BINDEVENT(loGrid.Column8, "AfterRowColChange", oManipulador, "CalculateTotal")

* Bind the event to Column9
BINDEVENT(loGrid.Column9, "AfterRowColChange", oManipulador, "CalculateTotal")

DEFINE CLASS Manipulador AS Session
LPARAMETERS nColIndex

* Define the event handler method directly
PROCEDURE CalculateTotal
   ? "CalculateTotal method called"  && No message was return ??
      loGrid.Column13.text1.value = VAL(loGrid.Column1.text1.value * loGrid.Column5.text1.value * loGrid.Column8.text1.value * loGrid.Column9.text1.value)

ENDPROC
enddefine
Thanks!
Luis

Hi Lutz and Borislav

I solve my problem with this:
Release GE_SNNOCALFIS

IF SFT.EDITING
   
    Public oHandler
    oHandler = Newobject( "myhandler" )

    oGrid = sft.pageframe1.page1.cont1.Grid1

    Bindevent(oGrid,"BeforeRowColChange",oHandler,"mymove")

ENDIF
 
DEFINE CLASS myhandler As Session

PROCEDURE mymove
Lparameters nColIndex
          SELECT FT

IF SFT.editing OR SFT.Adding

		Select FI

		If !Empty(FI.REF) And  (FI.qtt <> 0 And  ( FI.partes <> 0 And FI.altura <> 0 And FI.largura <> 0 And FI.espessura <> 0))


			SFT.pageframe1.page1.cont1.grid1.column13.text1.Value =( SFT.pageframe1.page1.cont1.grid1.column1.text1.Value * SFT.pageframe1.page1.cont1.grid1.column5.text1.Value *  SFT.pageframe1.page1.cont1.grid1.column8.text1.Value * SFT.pageframe1.page1.cont1.grid1.column9.text1.Value)

			Replace FI.u_cantidad With Round(( partes * altura * largura * espessura ),4)
			Replace FI.etiliquido With  Round( Round( FI.u_cantidad *((epv *(1-desconto/100)*(1-desc2/100)*(1-desc3/100)*(1-desc4/100)*(1-desc5/100)*(1-desc6/100))), 6 ) , 2)
		Else
			If !Empty(FI.REF) And  ( FI.qtt <> 0 And  ( FI.partes =  0 Or FI.altura = 0  Or FI.largura = 0  Or FI.espessura = 0) )
				Replace  FI.u_cantidad With FI.qtt
			Endif
		Endif

do fttots
do ftactval

ENDIF

ENDPROC

ENDDEFINE
Borislav,
Regarding your question i need to use BINDEVENT because the principal GRID of the program "sft.pageframe1.page1.cont1.Grid1" cannot be modify by because it is a program that I review and was not developed by me, so I do not have access to all the programming features,
the only possibility I have is to edit the screen in drawing mode and add a new grid where I have the possibility to add code in Xbase, this way from this new grid I delegate the instructions to the main Grid, which as I said, I cannot change or add new events, that´s why i use BINDEVENT .

In practice, when i change the value of one of these columns : SFT.pageframe1.page1.cont1.grid1.column1.text1.Value * SFT.pageframe1.page1.cont1.grid1.column5.text1.Value * SFT.pageframe1.page1.cont1.grid1.column8.text1.Value * SFT.pageframe1.page1.cont1.grid1.column9.text1.Value, i want instant result in grid on column13.

Also, Instead of referencing the column index, it is possible to control it via controlsource, in this case I believe it would be like this:
select fi
oGrid = SFT.Pageframe1.Page1.Cont1.Grid1
For i = 1 to oGrid.ColumnCount 

	If oGRid.Columns(i).controlsource == "FI.ALTURA"  &&By ControlSource
             		? oGRid.Columns(i).text1.value
	Endif
EndFor
That´s correct ?

Many thanks for your replies !

Best regards,
Luis
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform