Cargar array en Grid

HMG en Español

Moderator: Rathinagiri

jparada
Posts: 349
Joined: Fri Jan 23, 2009 5:18 pm
Has thanked: 3 times
Been thanked: 10 times

Cargar array en Grid

Post 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

User avatar
AUGE_OHR
Posts: 1303
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 243 times
Been thanked: 369 times

Post by AUGE_OHR »

try
<WindowName>.<GridName>.Refresh(.T.)
have fun
Jimmy

jparada
Posts: 349
Joined: Fri Jan 23, 2009 5:18 pm
Has thanked: 3 times
Been thanked: 10 times

Post 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

User avatar
AUGE_OHR
Posts: 1303
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 243 times
Been thanked: 369 times

Post 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
have fun
Jimmy

martingz
Posts: 332
Joined: Wed Nov 18, 2009 11:14 pm
Location: Mexico
Has thanked: 53 times
Been thanked: 31 times

Post 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)

jparada
Posts: 349
Joined: Fri Jan 23, 2009 5:18 pm
Has thanked: 3 times
Been thanked: 10 times

Post 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

User avatar
AUGE_OHR
Posts: 1303
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 243 times
Been thanked: 369 times

Post 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"
have fun
Jimmy

jparada
Posts: 349
Joined: Fri Jan 23, 2009 5:18 pm
Has thanked: 3 times
Been thanked: 10 times

Post 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

User avatar
AUGE_OHR
Posts: 1303
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 243 times
Been thanked: 369 times

Post 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
have fun
Jimmy

martingz
Posts: 332
Joined: Wed Nov 18, 2009 11:14 pm
Location: Mexico
Has thanked: 53 times
Been thanked: 31 times

Post 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

Post Reply