Scroll horizontal de un Grid limitado solo a última columna.

652 views
Skip to first unread message

Edgar Acevedo

unread,
Jan 5, 2015, 10:31:11 PM1/5/15
to publicesvfoxpro, Edgar Acevedo
Saludos respetables colegas:

Tengo un Grid que me funciona perfectamente bien.  Tiene 6 columnas cuyo contenido es tan ancho que debo activar la barra de "scroll" horizontal para poder ver las columnas de la derecha que quedan ocultas de la vista principal.
El caso es que no me agrada que la barra de Scroll permita desplazarse aún más allá de la 6ta. columna, como si existiera una séptima, (como les muestro en la siguiente imagen).




Mi consulta:  ¿Hay alguna propiedad del Grid o "truco" que no permita que el Scroll horizontal se mueva más allá de la última columna como se muestra en la imagen de arriba?  Me gustaría que el scroll permita mover solo hasta la última columna definida y que no muestre ese feo espacio inútil a la derecha de la útlima columna definida.

Anticipadamente, mil gracias por su atención a mi consulta.


Edgar Acevedo.


Fidel Charny

unread,
Jan 6, 2015, 7:13:47 AM1/6/15
to publice...@googlegroups.com, aper...@gmail.com
Aunque es una solución que no me gusta, podés probar con
SplitBar=.T.., Partition=.Columns(1).Width+17 , .LockColumnsLeft=1, .LockColumns=1
Fijate si te sirve.

edgar suarez kummers

unread,
Jan 6, 2015, 7:39:14 AM1/6/15
to publice...@googlegroups.com
Tocayo Edgar:
 
Te quiero comentar que Fidel Charny es de la SECRETA y además de la MODESTIA, dos organizaciones que hacen el bien y no miran a quien. Me ayudó demasiado bien en asuntos puntuales de mis aplicativos.
 
Si deseas mirar a qué me refiero mira el video siguiente:
Aunque hay otros además en este foro de esas características: LMG, César Chalom, Fernando D'Bozzo, gracias a todos ellos.
 
 
saludos

Víctor Hugo Espínola Domínguez

unread,
Jan 6, 2015, 11:29:47 AM1/6/15
to publice...@googlegroups.com
Hola Edgar

En el evento Scrolled del grid puedes calcular el ancho de la última columna:

*
*!*    Evento Scrolled del grid:
*
Lparameters nDirection

With Thisform
    If nDirection > 3  && horizontal scroll bar
        .SetRightmostColumnWidth
        .Draw()
    Endif
Endwith
*
*------------------------------------------------------------------------------------------------------------
*
*!*    Método Thisform.SetRightmostColumnWidth
*
With Thisform.MiGrid

* Calculate total width of columns in the grid starting at first visible column
    If .ColumnCount > 0
        Local nWidth, i, lCorrect, nRightColumn
        nWidth = 0
        lCorrect = .T.
* check to see if the rightmost column is in the visible portion of the grid
        For i = .LeftColumn To .ColumnCount
            nWidth = nWidth + .Columns(i).Width
            If nWidth > .Width
                lCorrect = .F.
                Exit && Total width exceeds grid with, no correction needed
            Endif
        Endfor
        If lCorrect
* First, we have to determine the column number of the rightmost column in the grid (which can change when columns are reordered)
            nRightColumn = 1
            For i = 1 To .ColumnCount
                If .Columns(i).ColumnOrder = .ColumnCount
*WAIT This.Columns(i).Header1.Caption WINDOW
                    nRightColumn =  i
                    Exit
                Endif
            Endfor
* Add the margin between the grid with and the total width of the visbile columns to the rightmost column
            .Columns(nRightColumn).Width = .Columns(nRightColumn).Width + (.Width - nWidth )
        Endif
    Endif

Endwith

Saludos,
Víctor.
Lambaré - Paraguay.

Edgar Acevedo

unread,
Jan 9, 2015, 11:20:09 PM1/9/15
to publicesvfoxpro
Estimado Victor Hugo Espínola:

Mil gracias por tu respuesta.  Me tomé unos días en responderte pues no solo quise darle "Copy-Paste" sino que entenderla bien en su mecanismo de función.  Como habrás notado, soy bastante lento para entender...
Pero una vez lo entendí bien, lo pude aplicar con unos pequeños ajustes mínimos al código que me proporcionaste.  Me funcionó haciéndolo de la siguiente manera

En el evento Scrolled del Grid agregué el siguiente código (como notarás, quité el .Draw() pues no entendí que hacía, y de todos modos me funcionó):

WITH THIS
   IF nDirection > 3  && horizontal scroll bar
      .SetRightmostColumnWidth
   ENDIF
ENDWITH

Creé un nuevo método en mi clase base de Grid al cual llamé SetRightmostColumnWidth y le puse el siguiente código (solo quitando el WAIT que en tu ejemplo estaba comentado):

WITH THIS
   * Calculate total width of columns in the grid starting at first visible column
   IF .COLUMNCOUNT > 0
      LOCAL nWidth, i, lCorrect, nRightColumn
      nWidth = 0
      lCorrect = .T.
      * Check to see if the rightmost column is in the visible portion of the grid
      FOR i = .LEFTCOLUMN TO .COLUMNCOUNT
         nWidth = nWidth + .COLUMNS(i).WIDTH
         IF nWidth > .WIDTH
            lCorrect = .F.
            EXIT && Total width exceeds grid width, no correction needed
         ENDIF
      ENDFOR
      IF lCorrect
         * First, we have to determine the column number of the rightmost column in the grid (which can change when columns are reordered)
         nRightColumn = 1
         FOR i = 1 TO .COLUMNCOUNT
            IF .COLUMNS(i).COLUMNORDER = .COLUMNCOUNT
               nRightColumn =  i
               EXIT
            ENDIF
         ENDFOR
         * Add the margin between the grid with and the total width of the visbile columns to the rightmost column
         .COLUMNS(nRightColumn).WIDTH = .COLUMNS(nRightColumn).WIDTH + (.WIDTH - nWidth )
      ENDIF
   ENDIF
ENDWITH

Te estoy muy agradecido por tomarte tu tiempo para responderme y haberme ayudado a resolver mi problema.

Edgar Acevedo.
Reply all
Reply to author
Forward
0 new messages