GRID Scrollbar

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

GRID Scrollbar

Post by Pablo César »

Yes Daniel, percentual we used at scrollbars at console in Clipper, but the main question is to know first visible row at grid when is scrolling and redrawing...

Probably the best way to advance is thru records skipping not by scrolling bars (this last is more difficult to know which is the first visible row).

There are following situations for displaying row at grid:
  1. When we click on specific record
  2. When move thry arrows key
  3. When scrollingbar are used
I've putted two buttons for Up/Down and one Spinner which can regularize the records skipping number (by 1 or 9) and I thought to be cool for disabling scrollbars, but this is not easy question for navigation..

Then reading MSDN I saw LVM_GETTOPINDEX which returns top visible record and then I used to assign for Value propose. It's works, but not 100%

Code: Select all

#include <hmg.ch>

#define SB_VERT             1
#define LVM_FIRST           0x1000
#define LVM_GETTOPINDEX     (LVM_FIRST+39)   

Function Main()
Local i, aItems:={}

For I=1 To 50
    Aadd(aItems,{"Item "+AllTrim(Str(i))})
Next

DEFINE WINDOW Form_1 AT 132 , 235 WIDTH 795 HEIGHT 328 TITLE "ScrollBars at both Grids" MAIN

    DEFINE GRID Grid_1
        ROW    30
        COL    20
        WIDTH  320
        HEIGHT 190
        ITEMS aItems
        VALUE Nil
        WIDTHS { 100 }
        HEADERS {'Items'}
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        ONCHANGE            ChangePos(This.Value)
		ONGOTFOCUS          Nil // Grid_Left()
		ONLOSTFOCUS         Nil // Grid_Right()
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONDBLCLICK Nil
        ONHEADCLICK Nil
        ONQUERYDATA Nil
        MULTISELECT .F.
        ALLOWEDIT .F.
        VIRTUAL .F.
        DYNAMICBACKCOLOR Nil
        DYNAMICFORECOLOR Nil
        COLUMNWHEN Nil
        COLUMNVALID Nil
        COLUMNCONTROLS Nil
        SHOWHEADERS .T.
        CELLNAVIGATION .F.
        NOLINES .F.
        HELPID Nil
        IMAGE Nil
        JUSTIFY Nil
        ITEMCOUNT Nil
        BACKCOLOR Nil
        FONTCOLOR Nil
        HEADERIMAGES Nil
        ROWSOURCE Nil
        COLUMNFIELDS Nil
        ALLOWAPPEND .F.
        ALLOWDELETE .F.
        BUFFERED .F.
        DYNAMICDISPLAY Nil
        ONSAVE Nil
        LOCKCOLUMNS Nil
    END GRID

    DEFINE GRID Grid_2
        ROW    30
        COL    440
        WIDTH  330
        HEIGHT 190
        ITEMS aItems
        VALUE Nil
        WIDTHS { 100 }
        HEADERS {'Items'}
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        ONCHANGE         ChangePos(This.Value)
        ONGOTFOCUS       Nil // Grid_Right()
        ONLOSTFOCUS      Nil // Grid_Right()
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONDBLCLICK Nil
        ONHEADCLICK Nil
        ONQUERYDATA Nil
        MULTISELECT .F.
        ALLOWEDIT .F.
        VIRTUAL .F.
        DYNAMICBACKCOLOR Nil
        DYNAMICFORECOLOR Nil
        COLUMNWHEN Nil
        COLUMNVALID Nil
        COLUMNCONTROLS Nil
        SHOWHEADERS .T.
        CELLNAVIGATION .F.
        NOLINES .F.
        HELPID Nil
        IMAGE Nil
        JUSTIFY Nil
        ITEMCOUNT Nil
        BACKCOLOR Nil
        FONTCOLOR Nil
        HEADERIMAGES Nil
        ROWSOURCE Nil
        COLUMNFIELDS Nil
        ALLOWAPPEND .F.
        ALLOWDELETE .F.
        BUFFERED .F.
        DYNAMICDISPLAY Nil
        ONSAVE Nil
        LOCKCOLUMNS Nil
    END GRID
	
	DEFINE BUTTON Button_1
        ROW    40
        COL    366
        WIDTH  48
        HEIGHT 30
        ACTION Grid_Up()
        CAPTION "&Up"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    90
        COL    366
        WIDTH  48
        HEIGHT 28
        ACTION Grid_Down()
        CAPTION "&Down"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE SPINNER Spinner_1
        ROW    200
        COL    360
        WIDTH  60
        HEIGHT 24
        RANGEMIN 1
        RANGEMAX 10
        VALUE 1
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        ONCHANGE Nil
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        TABSTOP .T.
        VISIBLE .T.
        WRAP .F.
        READONLY .F.
        INCREMENT 1
        BACKCOLOR Nil
        FONTCOLOR Nil
    END SPINNER
	
	DEFINE STATUSBAR FONT "Courier New" SIZE 9
        STATUSITEM PadC("",75)
    END STATUSBAR

END WINDOW
CREATE EVENT PROCNAME Check_Grid_Events()
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil

Function ChangePos(nRow)
Form_1.Grid_1.Value := SetProperty("Form_1","Grid_1","Value",nRow)
Form_1.Grid_2.Value := SetProperty("Form_1","Grid_2","Value",nRow)
Return Nil

Function Grid_Down()
Local nRow := GetProperty("Form_1","Grid_1","Value")

ChangePos(nRow + GetProperty("Form_1","Spinner_1","Value"))
Return Nil

Function Grid_Up()
Local nRow := GetProperty("Form_1","Grid_1","Value")

ChangePos(nRow - GetProperty("Form_1","Spinner_1","Value"))
Return Nil

Function GetScrollBarPos()
Local cControl := GetProperty("Form_1","FocusedControl")
Local nHandle_Left:=GetControlHandle ( "Grid_1", "Form_1" )
Local nHandle_Right:=GetControlHandle ( "Grid_2", "Form_1" )
Local nPos:=GetScrollPos ( If(cControl="Grid_1",nHandle_Left,nHandle_Right), 1 )
Local nRow:=GetProperty("Form_1",cControl,"Value")

SetScrollPos ( If(cControl="Grid_1",nHandle_Right,nHandle_Left), SB_VERT, nPos, .T. )
ChangePos(SendMessage( If(cControl="Grid_1",nHandle_Left,nHandle_Right), LVM_GETTOPINDEX, 0, 0 )+2)
Return Nil

Function Check_Grid_Events()
Local nMsg := EventMsg()
Local wParam := EventWPARAM()
Local lScrollMove:=.F.

If wParam <> Form_1.HANDLE
   DO CASE
      CASE nMsg == WM_KEYUP
           lScrollMove:=.T.
      CASE nMsg == WM_KEYDOWN
           lScrollMove:=.T.
      CASE nMsg == 161
	       If LoWord(wParam) < 8
           	  lScrollMove:=.T.
           EndIf
      CASE nMsg == WM_MOUSEWHEEL
           lScrollMove:=.T.
      OTHERWISE
		   Form_1.StatusBar.Item(1):=Str(nMsg)
   ENDCASE
   If lScrollMove
      GetScrollBarPos()
   Endif
Endif
Return Nil
This is a complex question (syncronized listviews). Here I found something (but in another programming language) :|

But let know something Serge: Why are you needing for this syncronized grids ? You need for what ?
Serge wrote:I try tomorrow. Now off to guitar playing!
Good guitar for you !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Amarante
Posts: 182
Joined: Fri Apr 27, 2012 9:44 pm
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL
Location: Araruama-RJ, Brazil

Re: GRID Scrollbar

Post by Amarante »

But let know something Serge: Why are you needing for this syncronized grids ? You need for what ?
Boa pergunta Pablo.
Imagino que seja para algum tipo de tabela de conversão ou análise... relacionando linhas e colunas, como aquelas que estão nas embalagens de alimentos relacionando a quantidade com as calorias... sei lá... só ele para dizer.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

GRID Scrollbar

Post by Pablo César »

I do not know exactly for what it will be used for. But I think it could be done at just one Grid (virtual, with arrays).
Considering the big efforts to get syncronizing... probably it would be good to reconsidere this question.

Daniel, have you tested my last example ? Quite good... not perfect but good.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Amarante
Posts: 182
Joined: Fri Apr 27, 2012 9:44 pm
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL
Location: Araruama-RJ, Brazil

Re: GRID Scrollbar

Post by Amarante »

Pablo,
Tested, looks good to me, but I do not know if Serge wants to move the bars or cells ... I have no idea.
And I'm testing something similar.
I do not use CellNavegation, imagine the situation:
A grid with multiple columns that go beyond the visible area, then the user navigates to the right until the desired column. say that is a column with names, and he chooses a filter and asks to update the grid, it happens that when it is done the refresh everything back to the first position.
If I used CellNavegation I could save the current line and column, do the refresh and set again in the row and column saved, but I do not want it.
So I'm trying to reposition itself in the row and column before the refresh (that with CellNavegation .F. Only saves the number of the line).
I'm trying to perhaps stubbornness, let's see if the routine wins me.
If you can I post here.
----------------------
Pablo,
Testei, me parece bom, mas eu não sei se o Serge quer movimentar as barras ou as células... não faço ideia.
E estou testando uma coisa parecida.
Eu não uso CellNavegation, imagine a situação:
Um grid com várias colunas que ultrapassam a área visivel, então o usuário navega para a direita até visualizar a coluna desejada. digamos que seja uma coluna com nomes, e ele escolhe um filtro e pede para atualizar o grid, acontece que quando é feito o refresh tudo volta para a primeira posição.
Se eu usasse CellNavegation eu poderia salvar a linha e coluna atual, fazer o refresh e setar novamente na linha e coluna salva, mas eu não quero isso.
Então estou tentando reposicionar na linha e coluna antes do refresh (que com CellNavegation .F. só salva o numero da linha).
Estou tentando talvez seja teimosia, vamos ver se a rotina me vence.
Se conseguir eu posto aqui.
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: GRID Scrollbar

Post by serge_girard »

Thanks all for help!

Just woke up and I will try later.

I 'need' this in order to compare the content of both tables and to quickly see the difference between the both.

Scrolling down synchronically is main goal but of course left and right would be great too...!

Anyway I'm happy with all your help!

Serge
There's nothing you can do that can't be done...
Post Reply