locked
Highlighting a row of cells in a grid RRS feed

  • Question

  • Hello everybody,

    How do you highlight a row of cells in a grid if the grid's data source does background processing on a per record basis?

    Thank you very much.

    Yong

     

    Wednesday, August 24, 2011 2:56 AM

Answers

  • Do you want to position the highlight on the record currently processed? In any case, check HighlightStyle property for the grid (VFP9).
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    • Marked as answer by Martin_Xie Wednesday, September 7, 2011 1:48 AM
    Wednesday, August 24, 2011 3:07 AM
  • Hi Yong,

    I just created a simple form, which shows that in an rather untouched grid this will work fine.

    In your case, there seems to be some code in your class/form/gridobj that renders this behaviour obsolet.

    DEFINE CLASS frm_demo AS form
    
    	Top = 0
    	Left = 0
    	DoCreate = .T.
    	Caption = "Form1"
    	Name = "Form1"
    
    	ADD OBJECT grid1 AS grid WITH ;
    		Height = 200, ;
    		Left = 15, ;
    		RecordSource = "crsTest", ;
    		Top = 25, ;
    		Width = 245, ;
    		HighlightStyle = 2, ;
    		AllowCellSelection = .F., ;
    		Name = "Grid1"
    
    	ADD OBJECT command1 AS commandbutton WITH ;
    		Top = 60, ;
    		Left = 275, ;
    		Height = 27, ;
    		Width = 84, ;
    		Caption = "Down", ;
    		Name = "Command1"
    
    	ADD OBJECT command2 AS commandbutton WITH ;
    		Top = 25, ;
    		Left = 275, ;
    		Height = 27, ;
    		Width = 84, ;
    		Caption = "Up", ;
    		Name = "Command2"
    
    	ADD OBJECT command3 AS commandbutton WITH ;
    		Top = 115, ;
    		Left = 275, ;
    		Height = 27, ;
    		Width = 84, ;
    		Caption = "Job", ;
    		Name = "Command3"
    
    	PROCEDURE Unload
    		USE IN SELECT([crsTest])
    	ENDPROC
    
    	PROCEDURE Load
    		CREATE CURSOR crsTest (feld1 c(10))
    		INSERT INTO crsTest(feld1) VALUES ([one])
    		INSERT INTO crsTest(feld1) VALUES ([two])
    		INSERT INTO crsTest(feld1) VALUES ([three])
    		INSERT INTO crsTest(feld1) VALUES ([four])
    		INSERT INTO crsTest(feld1) VALUES ([five])
    		INSERT INTO crsTest(feld1) VALUES ([six])
    		INSERT INTO crsTest(feld1) VALUES ([seven])
    		INSERT INTO crsTest(feld1) VALUES ([eight])
    		INSERT INTO crsTest(feld1) VALUES ([nine])
    		INSERT INTO crsTest(feld1) VALUES ([ten])
    		GO TOP IN crsTest
    	ENDPROC
    
    	PROCEDURE grid1.AfterRowColChange
    		LPARAMETERS nColIndex
    		WITH This
    			IF RECNO( .RecordSource ) = RECCOUNT( .RecordSource )
    				.AllowCellSelection = .T.
    			ELSE 
    				.AllowCellSelection = .F.
    			ENDIF
    			.Refresh
    		ENDWITH
    	ENDPROC
    
    	PROCEDURE command1.Click
    		SKIP IN crsTest
    		Thisform.Grid1.Refresh
    	ENDPROC
    
    	PROCEDURE command2.Click
    		SKIP -1 IN crsTest
    		Thisform.Grid1.Refresh
    	ENDPROC
    
    	PROCEDURE command3.Click
    		GO TOP IN crsTest
    		Thisform.grid1.Refresh
    		FOR i = 1 TO RECCOUNT( [crsTest] )
    
    			REPLACE feld1 WITH [+] + feld1 IN crsTest
    			SKIP IN crsTest
    			Thisform.grid1.Refresh
    			WAIT WINDOW TIMEOUT 1
    		ENDFOR 
    	ENDPROC
    
    ENDDEFINE
    
    



    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    • Proposed as answer by Pavel Celba Wednesday, August 24, 2011 12:52 PM
    • Marked as answer by Yong Mallare Thursday, August 25, 2011 1:54 AM
    Wednesday, August 24, 2011 8:54 AM
    Answerer
  •  Ms Naomi,

    The HighLightStyle property is already set to 2-Current Row highlighting enabled with visual persistence ma'm. But how come as the records are being processed in the background, the highlighting of the row does not move ie if record = 2 the 2nd row in the grid should be highlighted..

    Thank you...

    Yong

    • Marked as answer by Yong Mallare Thursday, August 25, 2011 1:54 AM
    Wednesday, August 24, 2011 3:18 AM

All replies

  • Do you want to position the highlight on the record currently processed? In any case, check HighlightStyle property for the grid (VFP9).
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    • Marked as answer by Martin_Xie Wednesday, September 7, 2011 1:48 AM
    Wednesday, August 24, 2011 3:07 AM
  •  Ms Naomi,

    The HighLightStyle property is already set to 2-Current Row highlighting enabled with visual persistence ma'm. But how come as the records are being processed in the background, the highlighting of the row does not move ie if record = 2 the 2nd row in the grid should be highlighted..

    Thank you...

    Yong

    • Marked as answer by Yong Mallare Thursday, August 25, 2011 1:54 AM
    Wednesday, August 24, 2011 3:18 AM
  • May be you need to refresh the grid? Or set focus to it?

    Does your process involve scanning the source (e.g. moving the record pointer)?


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Wednesday, August 24, 2011 3:33 AM
  •  

    Yes ma'm, it does involve scanning every record of the source cursor...

    Wednesday, August 24, 2011 3:47 AM
  • Hi Yong,

    you will have to refresh the grid after each skip in your background processing routine.

    As you already set the HighlightStyle to 2 the grid will then be displayed correctly.


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    Wednesday, August 24, 2011 6:11 AM
    Answerer
  • Sir Tom,

    I have already placed the refreshing of the grid everytime the processing finishes for each record. The highlighted row in my grid only stays as it is (on the first row in the grid), eventhough in the background movement in the records are taking place. i also tried placing a "KEYBOARD {'DNARROW'}" in the loop but to no avail. What could be wrong with this "THISFORM.Grid1.Refresh" ?

    Thank you very much sir for the response...

    Yong

    Wednesday, August 24, 2011 8:39 AM
  • Hi Yong,

    I just created a simple form, which shows that in an rather untouched grid this will work fine.

    In your case, there seems to be some code in your class/form/gridobj that renders this behaviour obsolet.

    DEFINE CLASS frm_demo AS form
    
    	Top = 0
    	Left = 0
    	DoCreate = .T.
    	Caption = "Form1"
    	Name = "Form1"
    
    	ADD OBJECT grid1 AS grid WITH ;
    		Height = 200, ;
    		Left = 15, ;
    		RecordSource = "crsTest", ;
    		Top = 25, ;
    		Width = 245, ;
    		HighlightStyle = 2, ;
    		AllowCellSelection = .F., ;
    		Name = "Grid1"
    
    	ADD OBJECT command1 AS commandbutton WITH ;
    		Top = 60, ;
    		Left = 275, ;
    		Height = 27, ;
    		Width = 84, ;
    		Caption = "Down", ;
    		Name = "Command1"
    
    	ADD OBJECT command2 AS commandbutton WITH ;
    		Top = 25, ;
    		Left = 275, ;
    		Height = 27, ;
    		Width = 84, ;
    		Caption = "Up", ;
    		Name = "Command2"
    
    	ADD OBJECT command3 AS commandbutton WITH ;
    		Top = 115, ;
    		Left = 275, ;
    		Height = 27, ;
    		Width = 84, ;
    		Caption = "Job", ;
    		Name = "Command3"
    
    	PROCEDURE Unload
    		USE IN SELECT([crsTest])
    	ENDPROC
    
    	PROCEDURE Load
    		CREATE CURSOR crsTest (feld1 c(10))
    		INSERT INTO crsTest(feld1) VALUES ([one])
    		INSERT INTO crsTest(feld1) VALUES ([two])
    		INSERT INTO crsTest(feld1) VALUES ([three])
    		INSERT INTO crsTest(feld1) VALUES ([four])
    		INSERT INTO crsTest(feld1) VALUES ([five])
    		INSERT INTO crsTest(feld1) VALUES ([six])
    		INSERT INTO crsTest(feld1) VALUES ([seven])
    		INSERT INTO crsTest(feld1) VALUES ([eight])
    		INSERT INTO crsTest(feld1) VALUES ([nine])
    		INSERT INTO crsTest(feld1) VALUES ([ten])
    		GO TOP IN crsTest
    	ENDPROC
    
    	PROCEDURE grid1.AfterRowColChange
    		LPARAMETERS nColIndex
    		WITH This
    			IF RECNO( .RecordSource ) = RECCOUNT( .RecordSource )
    				.AllowCellSelection = .T.
    			ELSE 
    				.AllowCellSelection = .F.
    			ENDIF
    			.Refresh
    		ENDWITH
    	ENDPROC
    
    	PROCEDURE command1.Click
    		SKIP IN crsTest
    		Thisform.Grid1.Refresh
    	ENDPROC
    
    	PROCEDURE command2.Click
    		SKIP -1 IN crsTest
    		Thisform.Grid1.Refresh
    	ENDPROC
    
    	PROCEDURE command3.Click
    		GO TOP IN crsTest
    		Thisform.grid1.Refresh
    		FOR i = 1 TO RECCOUNT( [crsTest] )
    
    			REPLACE feld1 WITH [+] + feld1 IN crsTest
    			SKIP IN crsTest
    			Thisform.grid1.Refresh
    			WAIT WINDOW TIMEOUT 1
    		ENDFOR 
    	ENDPROC
    
    ENDDEFINE
    
    



    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    • Proposed as answer by Pavel Celba Wednesday, August 24, 2011 12:52 PM
    • Marked as answer by Yong Mallare Thursday, August 25, 2011 1:54 AM
    Wednesday, August 24, 2011 8:54 AM
    Answerer
  • Sir Tom, Ma'm Naomi,

    I have already found the reason for my problem, it was not pointing at the right cursor where the grid is binded to, so i made sure that during processing it will point to the right cursor. Thank you very much for your time and assistance. Please dont stop helping us newbies in this arena. God Bless!

    Yong

    Thursday, August 25, 2011 1:54 AM