Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid Congelado
Message
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00717267
Message ID:
00723538
Views:
7
Hola, Mauricio.

>definitivamente me da mucha pena estar con tanta preguntadera, pero, seria posible que me enviaras tu clase.

Aquí pego la clase. Ten en cuenta algunas cosas:

1) Lo que la clase hace es crear un grid de una sola fila en la parte inferior del principal, acortando la altura de este para que ocupen el mismo espacio visual que uno utilizó en el formulario.

La clase se encarga también de mantener sincronizadas las columnas si se produce un scroll horizontal, de modo que los totales permanecen siempre debajo de la columna correspondiente.

2) Este código es generado por el Class Browser sobre la clase visual, por lo que tal vez no funcione directamente. Lo ideal es estudiarlo y ubicarlo manualmente en una subclase visual de tu grid.

3) Verás también que esta clase es una subclase de mi grid genérigo (maaGrid), por lo que puede dar por sentado alguna característica particular que el tuyo no tenga (aunque no creo).

Finalmente, si tienes alguna dificultad me vas preguntando. Realmente escribimos esto hace años (yo hice el diseño, pero el código final no es mío, e incluso hubo retoques de un par de manos), así que no lo tengo de lo más fresco, pero mirándolo por encima me parce más que claro, y los comentarios, si escasos, están en español.
**************************************************
*-- Class:        maatotalgrid (i:\desarrol\@wlib5\maaclass.vcx)
*-- ParentClass:  maagrid (i:\desarrol\@wlib5\maaclass.vcx)
*-- BaseClass:    grid
*-- Time Stamp:   07/27/00 10:58:05 AM
*-- Grid con línea de totales.
*
DEFINE CLASS maatotalgrid AS maagrid


  Name = "maatotalgrid"


  *-- Arma el grid y el cursor de los totales. Reduce el grid inicial para que el 
  *-- grid de totales se encuentre dentro del rango especificado.
  PROCEDURE armatotales
    LParameter tcFieldsSum

    if param() = 0 or empty( tcFieldsSum )    && No hay campos para sumar
      return
    endif

    Local lcNameGridTot, lcRefGridTot, lcRecSourceMain, lcRecSourceTot, ;
     lnSeparacion, lnHeightGridTot

    *-- El nombre del grid y del recordSource de totales es igual 
    *-- a los correspondientes del grid inicial + "T"

    lcNameGridTot = allt(this.name) + "T"    && Nombre del grid de totales
    lcRefGridTot  = "thisform." + lcNameGridTot  && referencia al grid de totales

    thisform.lockScreen = .t.

    lnSeparacion = 1    && Separación entre grids

    lnHeightGridTot = 25    && Alto del Grid de Totales

    if type( lcRefGridTot ) = "O"
      thisform.RemoveObject( lcNameGridTot )

      lnTopTotales = this.height + this.top + lnSeparacion
    else

      lnTopTotales = this.height + this.top - lnHeightGridTot
      this.height = this.height - lnHeightGridTot - lnSeparacion
    endif

    thisform.AddObject( lcNameGridTot , "maagrid" )     && agrega el grid al form

    ** Inicializa datos del grid de totales

    with &lcRefGridTot

      .RecordSource   = ""
      .left      = this.left
      .top      = lnTopTotales
      .height      = lnHeightGridTot
      .headerHeight  = 0

      lnSuprime = iif( this.scrollBars = 0, 0 , 17 )

      .ColumnCount  = this.columnCount
      .width       = this.width - lnSuprime
      .scrollBars     = 0
    endwith

    lcRecSourceMain = this.recordSource
    lcRecSourceTot  = allt(this.recordSource) + "T"

    *-- Arma las columnas del grid de totales 
    for lnCol = 1 to this.columnCount
      with &lcRefGridTot
        with .Columns(lnCol)

          .name = this.Columns(lnCol).name
          .RemoveObject( "text1" )  && Elimina el control por default

          .dynamicForeColor = this.Columns(lnCol).dynamicForeColor

          .visible = this.Columns(lnCol).visible
          .sparse  = this.Columns(lnCol).sparse
          .width   = this.Columns(lnCol).width

          lcControlCol = this.columns(lnCol).controls(2).name
          lcClassObj   = this.columns(lnCol).controls(2).class

          .addObject( lcControlCol , lcClassObj )

          with .Controls(1)
            .FontSize  = this.columns(lnCol).Controls(1).FontSize
            .Alignment = this.columns(lnCol).Controls(1).Alignment
            .FontName  = this.columns(lnCol).Controls(1).FontName
            .FontBold  = this.columns(lnCol).Controls(1).FontBold
            .caption   = ""
            .name      = this.columns(lnCol).Controls(1).name
          endwith

          with .Controls(2)
            .visible   = this.columns(lnCol).Controls(2).visible
            .format    = this.columns(lnCol).Controls(2).format
            .InputMask = this.columns(lnCol).Controls(2).InputMask
          endwith

        endwith

      endwith
    next

    *-- Crea el cursor de totales y realiza la suma de los campos indicados
    tcFieldsSum = allt(tcFieldsSum)
    lcFieldsMem  = "m." + strTran( tcFieldsSum , "," , ",m." )

    =AFields( laFields , lcRecSourceMain )
    create cursor (lcRecSourceTot) from array laFields

    scatter memvar blank

    select (lcRecSourceMain)

    sum &tcFieldsSum to &lcFieldsMem

    insert into (lcRecSourceTot) from memvar

    with &lcRefGridTot
      .visible = .t.
      .recordSource = lcRecSourceTot
    endwith

    select (lcRecSourceMain)
    locate

    thisform.lockScreen = .f.

    thisform.refresh()
  ENDPROC


  PROCEDURE AfterRowColChange
    LPARAMETERS nColIndex

    Local lcNameGridTot, lcRefGridTot

    lcNameGridTot = allt(this.name) + "T"    && Nombre del grid de totales
    lcRefGridTot  = "thisform." + lcNameGridTot       && referencia al grid de totales

    if type( lcRefGridTot ) = "O"

      *-- Método: Verifica que la primer columna del grid de datos sea 
      *-- igual a la del grid. Si no llegara a ser la misma desplaza el grid 
      *-- de totales hasta que la columna sea la misma

      with &lcRefGridTot

        lnLeftColMain  = this.LeftColumn
        lnLeftColTotal = .LeftColumn

        lnDifAbs = abs( lnLeftColMain - lnLeftColTotal )

        if lnLeftColMain # lnLeftColTotal

          if lnDifAbs > 2
            thisform.LockScreen = .t.
          endif

          if lnLeftColMain > lnLeftColTotal 
            for f = 1 to lnDifAbs
              .doScroll( 5 )

              if lnLeftColMain = .LeftColumn
                exit
              endif
            next
          else
            for f = 1 to lnDifAbs
              .doScroll( 4 )
              if lnLeftColMain = .LeftColumn
                exit
              endif
            next
          endif

          if lnDifAbs > 2
            thisform.LockScreen = .f.
          endif
        endif
      endwith
    endif
  ENDPROC


ENDDEFINE
*
*-- EndDefine: maatotalgrid
**************************************************
Espero que te sea útil.

Saludos,
Previous
Reply
Map
View

Click here to load this message in the networking platform