Page 1 of 2

Cargar array en Grid

Posted: Wed Feb 24, 2021 10:35 pm
by jparada
Hola,
Disculpen mi ignorancia por favor...

Puse un Grid con un array inicial vacío

Code: Select all

LOCAL movtosBanco := { }

@ 10,10 GRID Grid1 ;
WIDTH 760 ;
HEIGHT 240 ;
HEADERS { 'Fecha','Descripcion','Cargo', 'Abono'} ;
WIDTHS {90,400,110,110};
ITEMS movtosBanco ;            
JUSTIFY { GRID_JTFY_LEFT, GRID_JTFY_LEFT, GRID_JTFY_RIGHT, GRID_JTFY_RIGHT } ;
CELLNAVIGATION 
Luego un botón para llamar la función que genera la información y llenar el array

Code: Select all

FUNCTION obtenerDatos()  	
    AAdd( aData, { aTokens[1], aTokens[2], aTokens[3], aTokens[4] }  )  
RETURN (aData)
Cómo indico para refrescar el Grid y que despliegue los datos obtenidos.

Saludos,
Javier

Re: Cargar array en Grid

Posted: Wed Feb 24, 2021 11:02 pm
by AUGE_OHR
try
<WindowName>.<GridName>.Refresh(.T.)

Re: Cargar array en Grid

Posted: Wed Feb 24, 2021 11:23 pm
by jparada
AUGE_OHR wrote: Wed Feb 24, 2021 11:02 pm try
<WindowName>.<GridName>.Refresh(.T.)
Hola Jimmy,

Eso ya lo había intentado, pero falta cómo le vuelves a asignar el valor a ITEMS, no sé si me explico?.

Saludos,
Javier

Re: Cargar array en Grid

Posted: Thu Feb 25, 2021 1:33 am
by AUGE_OHR
hi,

are you using DBF or ARRAY :?:

---

Code: Select all

USE ONCHANGE Dochange( This.Window, This.Name ... )

PROCEDURE DoChange( cForm, cObj )
   ...
#IFDEF Use_DataBrowse
   RefreshBrowseLine( cBroMacro, "BrowserView", aStruc )
#ELSE
   RefreshCurrent( cBroMacro, "BrowserView" )
#ENDIF

ARRAY

Code: Select all

PROCEDURE RefreshCurrent( cForm, cBrowse )
LOCAL hBrowse := GetControlHandle( cBrowse, cForm )
LOCAL nRecord := GetProperty( cForm, cBrowse, "VALUE" )
   ListView_RedrawItems( hBrowse, nRecord, nRecord )
RETURN

DBF

Code: Select all

PROCEDURE RefreshBrowseLine( cForm, cBrowse, aStruc )
LOCAL i, iMax
LOCAL cField, cType, xValue
LOCAL h, nIdx, nRow

   nIdx := GetControlIndex( cBrowse, cForm )
   h := GetControlHandle( cBrowse, cForm )
   nRow := LISTVIEW_GETFIRSTITEM( h )   // this function returns current screen row number

   iMax := LEN( aStruc )
   FOR i := 1 TO iMax
      cField := aStruc[ i ] [ DBS_NAME ]
      cType := aStruc[ i ] [ DBS_TYPE ]
      xValue := &( cField )

      DO CASE
         CASE cType == "N" .OR. cType == "I"
            xValue := hb_ntos( xValue )
         CASE cType == "D"
            xValue := HB_VALTOSTR( xValue )
         CASE cType == "L"
            xValue := HB_VALTOSTR( xValue )

         CASE cType == "@" .OR. cType = "T"
            xValue := hb_TSToStr( xValue )
      ENDCASE
      SetProperty( cForm, cBrowse, "CELL", nRow, i, xValue )
   NEXT i

RETURN

Re: Cargar array en Grid

Posted: Thu Feb 25, 2021 3:29 am
by martingz
FUNCTION obtenerDatos()
AAdd( aData, { aTokens[1], aTokens[2], aTokens[3], aTokens[4] } )
form.grid_1.Additem(aData)
form.grid_1.refresh
RETURN (aData)

Re: Cargar array en Grid

Posted: Thu Feb 25, 2021 5:52 pm
by jparada
martingz wrote: Thu Feb 25, 2021 3:29 am FUNCTION obtenerDatos()
AAdd( aData, { aTokens[1], aTokens[2], aTokens[3], aTokens[4] } )
form.grid_1.Additem(aData)
form.grid_1.refresh
RETURN (aData)
Hola Martín,

Me da error en Additem

Saludos,
Javier

Re: Cargar array en Grid

Posted: Thu Feb 25, 2021 10:38 pm
by AUGE_OHR
hi

seem you have not "append" new Items ... before "refresh"

Code: Select all

PROCEDURE Add2Grid(aTokens)
LOCAL aLine := { aTokens[1], aTokens[2], aTokens[3], aTokens[4] } 
   Win_1.Grid_1.AddItem( aLine )
   Win_1.Grid_1.refresh
RETURN
after "Additem" Pointer "is" on right Position so it is not need to "re-position"

Re: Cargar array en Grid

Posted: Fri Feb 26, 2021 3:00 am
by jparada
Hola Jimmy,

No logro ver la diferencia entre tu código y el código de Martín o no entiendo a qué te refieres.

Saludos,
Javier

Re: Cargar array en Grid

Posted: Fri Feb 26, 2021 4:53 pm
by AUGE_OHR
hi

you need to
a.) add data to Source
b.) Additem() to GRID
c.) refresh() GRID to "show" new data

---

Sample

Code: Select all

   acItems := DIRECTORY("C:\TEMP\*.*")

   GRID Grid_1
   ITEMS acItems 
now i copy a File to C:\TEMP\ and want to "update" GRID include new file

this does NOT help to "show" new File in GRID

Code: Select all

   AADD(acItem, aLine)
it does add aLine to Source only

you need

Code: Select all

   Win_1.Grid_1.AddItem( aLine )
to add Item to GRID and "show" it

Code: Select all

   Win_1.Grid_1.refresh
on End "re-paint" GRID to show new file in last Row of GRID

---

when have a Array as Source you also can use GRID Property "VIRTUAL"

Code: Select all

#IFDEF Use_Virtual
      SetProperty( "Win_1", "Grid_1", "ITEMCOUNT", LEN( aDir ) )
#ELSE
      FOR i := 1 TO iMax
            aLine := { aDir[ i ] [ F_NAME ], ;
                       aDir[ i ] [ F_SIZE ], ;
                       aDir[ i ] [ F_DATE ], ;
                       aDir[ i ] [ F_TIME ], ;
                       aDir[ i ] [ F_ATTR ] }

            Domethod( "Win_1", "Grid_1", "AddItem", aLine )
      NEXT
#ENDIF
      Win_1.Grid_1.refresh
so what you need for "VIRTUAL"

Code: Select all

   AADD(acItem, aLine) 
   Win_1.Grid_1.ItemCount := LEN(acItem)
   Win_1.Grid_1.refresh

Re: Cargar array en Grid

Posted: Fri Feb 26, 2021 7:23 pm
by martingz
Javier disculpa la tardanza en contestar

prueba asi
form.grid_1.Additem({aTokens[1], aTokens[2], aTokens[3], aTokens[4]})
form.grid_1.refresh


saludos