Page 1 of 2

Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 6:57 pm
by Amarante
Please, anyone know the reason for this behavior on the grid?

Code: Select all

****************************************************************************
* TEST VIRTUAL GRID
****************************************************************************
#include "hmg.ch"

FUNCTION Main()

PRIVATE aMyData  := {}
PRIVATE bColor := { || IIF( This.CellRowIndex / 2 == INT( This.CellRowIndex / 2 ) , { 222,222,222 } , { 255,255,255 } ) }

DEFINE WINDOW Win_Grid ;
		AT 0,0 ;
		WIDTH 450 ;
		HEIGHT 400 ;
		TITLE "Test Virtual Grid" ;
		MAIN

  DEFINE GRID My_Grid
    ROW 10
    COL 10
    WIDTH 400
    HEIGHT 330
    HEADERS { "Number", "Date", "String" }
    WIDTHS { 60, 100, 140 }
    DYNAMICBACKCOLOR { bColor , bColor , bColor }
    ITEMS aMyData
    ITEMCOUNT LEN( aMyData )
    *---------------------------------------------------------------------------
    * Parameters for Virtual Grid
    *---------------------------------------------------------------------------
    VIRTUAL .T.
    ONQUERYDATA Grid_Query()
  END GRID

END WINDOW

*---------------------------------------------------------------------------
* Prepare Mounting Grid
*---------------------------------------------------------------------------
Create_Data()

CENTER WINDOW Win_Grid
ACTIVATE WINDOW Win_Grid

Return


****************************************************************************
STATIC FUNCTION Create_Data()
****************************************************************************
LOCAL x
aMyData := {}
FOR x = 1 TO 100
  AADD( aMyData, { x, DATE() - x, "TESTE" } )
NEXT x
*---------------------------------------------------------------------------
* Entering Data on the Grid
*---------------------------------------------------------------------------
DECLARE WINDOW Win_Grid
Win_Grid.My_Grid.DeleteAllItems
IF LEN( aMyData ) > 0
  *---------------------------------------------------------------------------
  * Sets the current position of the item in the grid
  *---------------------------------------------------------------------------
  Win_Grid.My_Grid.ItemCount := LEN( aMyData )
  Win_Grid.My_Grid.Value     := 1
  Win_Grid.My_Grid.Refresh
  Win_Grid.My_Grid.SetFocus
ENDIF

RETURN NIL


****************************************************************************
FUNCTION Grid_Query()
****************************************************************************
LOCAL nRow_   := This.QueryRowIndex
LOCAL nCol_   := This.QueryColIndex
This.QueryData := Convert2Sstring( aMyData[ nRow_, nCol_ ] )

RETURN NIL


****************************************************************************
FUNCTION Convert2Sstring( xData_ )
* converting to string
****************************************************************************
LOCAL xReturn_ := ""

*---------------------------------------------------------------------------
* Character
*---------------------------------------------------------------------------
IF VALTYPE( xData_ ) = "C"
  xReturn_ := xData_
*---------------------------------------------------------------------------
* Numerical
*---------------------------------------------------------------------------
ELSEIF VALTYPE( xData_ ) == "N"
  xReturn_ := LTRIM( STR( xData_ ) )
*---------------------------------------------------------------------------
* Date
*---------------------------------------------------------------------------
ELSEIF VALTYPE( xData_ ) == "D"
  xReturn_ := DTOC( xData_ )
*---------------------------------------------------------------------------
* The data can not be converted
*---------------------------------------------------------------------------
ELSE
  xReturn_ := ""
ENDIF

RETURN xReturn_
See the picture

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 7:10 pm
by Amarante
Here are the files for those who want to test

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 7:47 pm
by andyglezl
Hola Amarante

Que yo sepa, el Grid solo maneja datos tipo "caracter"
(Nota: Estoy hablando del GRID, no del array)

Tendrias que poner:

FOR x = 1 TO 100
AADD( aMyData, { STR(x), DTOC(DATE() - x), "TESTE" } )
NEXT x
----------------------------------------------------------
Hello Amarante

To my knowledge, the Grid only handles data type "character"
(Note: I'm talking about GRID, not array)

You'd have to put:
FOR x = 1 TO 100
AADD( aMyData, { STR(x), DTOC(DATE() - x), "TESTE" } )
NEXT x

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 8:20 pm
by Amarante
andyglezl wrote:Hola Amarante

Que yo sepa, el Grid solo maneja datos tipo "caracter"
(Nota: Estoy hablando del GRID, no del array)

Tendrias que poner:

FOR x = 1 TO 100
AADD( aMyData, { STR(x), DTOC(DATE() - x), "TESTE" } )
NEXT x
----------------------------------------------------------
Hello Amarante

To my knowledge, the Grid only handles data type "character"
(Note: I'm talking about GRID, not array)

You'd have to put:
FOR x = 1 TO 100
AADD( aMyData, { STR(x), DTOC(DATE() - x), "TESTE" } )
NEXT x

andyglezl, Thanks for answering.
But when I use queryData I'm sending data strings for the grid, I urge is that I do not understand.
If you change the routine of converting data to string columns appear normal, ie, does not seem to be the reason that you mentioned.
see example changed

Code: Select all

****************************************************************************
FUNCTION Convert2Sstring( xData_ )
* converting to string
****************************************************************************
LOCAL xReturn_ := ""

*---------------------------------------------------------------------------
* Character
*---------------------------------------------------------------------------
IF VALTYPE( xData_ ) = "C"
  xReturn_ := xData_
*---------------------------------------------------------------------------
* Numerical
*---------------------------------------------------------------------------
ELSEIF VALTYPE( xData_ ) == "N"
  xReturn_ := str( xData_, 35 )       //  LTRIM( STR( xData_ ) )
*---------------------------------------------------------------------------
* Date
*---------------------------------------------------------------------------
ELSEIF VALTYPE( xData_ ) == "D"
  xReturn_ := REPLICATE( DTOC( xData_ ) + ", ", 4 )      // DTOC( xData_ )
*---------------------------------------------------------------------------
* The data can not be converted
*---------------------------------------------------------------------------
ELSE
  xReturn_ := ""
ENDIF

RETURN xReturn_

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 8:25 pm
by Amarante
The problem is that I can not display a simple CTOD () or str ().
It seems to be related to the size of the column, but I still can not find the reason. :( :roll:

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 8:29 pm
by srvet_claudio
Remove the grid this line

Code: Select all

  DEFINE GRID My_Grid
    ROW 10
    COL 10
    WIDTH 400
    HEIGHT 330
    HEADERS { "Number", "Date", "String" }
    WIDTHS { 60, 100, 140 }
    DYNAMICBACKCOLOR { bColor , bColor , bColor }
    ITEMS aMyData
//    ITEMCOUNT LEN( aMyData )  <-- REMOVE
    *---------------------------------------------------------------------------
    * Parameters for Virtual Grid
    *---------------------------------------------------------------------------
    VIRTUAL .T.
    ONQUERYDATA Grid_Query()
  END GRID
because at this level LEN( aMyData ) = 0

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 8:40 pm
by Amarante
srvet_claudio wrote:Remove the grid this line

Code: Select all

  DEFINE GRID My_Grid
    ROW 10
    COL 10
    WIDTH 400
    HEIGHT 330
    HEADERS { "Number", "Date", "String" }
    WIDTHS { 60, 100, 140 }
    DYNAMICBACKCOLOR { bColor , bColor , bColor }
    ITEMS aMyData
//    ITEMCOUNT LEN( aMyData )  <-- REMOVE
    *---------------------------------------------------------------------------
    * Parameters for Virtual Grid
    *---------------------------------------------------------------------------
    VIRTUAL .T.
    ONQUERYDATA Grid_Query()
  END GRID
because at this level LEN( aMyData ) = 0
Claudio, I made the suggested change but unfortunately the error remains.

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 9:36 pm
by EduardoLuis
Hola Amarante:

Disculpa, que te pregunte, pero has hecho el upgrade de la versió 3.15 que publicó Claudio ?
Yo he testeado tu grid demo y funciona perfectamente.- Si no lo has hecho, descarga el patch y actualiza tu versión.-

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 9:38 pm
by srvet_claudio
EduardoLuis wrote:Hola Amarante:

Disculpa, que te pregunte, pero has hecho el upgrade de la versió 3.15 que publicó Claudio ?
Yo he testeado tu grid demo y funciona perfectamente.- Si no lo has hecho, descarga el patch y actualiza tu versión.-
+1

Re: Strange behavior in virtual grid

Posted: Mon Aug 26, 2013 9:43 pm
by Amarante
I have installed the versions:
HMG.3.1.5 Demos patch2.rar
HMG 3.1.5 patch2.rar
If there are others please let me know.