Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

MLG Questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fredrick Ughimi
    replied
    Hello Mike,

    I have finally got MLG to refresh. It was easy really but hard to find for me. I only had to call my FillGrid method after my INSERT routine. Woks fine. No endless loop like my last trial. In the FillGrid method I included your suggestions. Thanks a lot.

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hi Mike,

    Yeah it did caused endless loop after further tests.

    Would try your suggestion and get back to you.

    Best regards.

    Leave a comment:


  • Mike Doty
    replied
    I do not know if your paint method will cause a problem.
    Filling the grid in the Paint doesn't seem right (could cause endless loop?)

    No form has to be reloaded with MLG_PutEx ghGrid,gsArray(),-4,0 and it refreshes the grid.
    Here is a demo that scrolls the grid as the array gets bigger by 1-row each time the button is clicked and WM_PAINT is not used.
    The docs say refresh may be unreliable so use
    'CASE %WM_PAINT
    ' CONTROL REDRAW CBHNDL,%Grid1

    Please try this code to see if it refreshes.
    If it does then maybe contact the author of your visual designer.
    Tested only using Windows 10.

    Code:
    GLOBAL ghDlg,ghGrid,gCounter AS DWORD
    GLOBAL gsArray() AS STRING
    %Button = 500
    %Grid  =1000
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "mlg.inc"
    FUNCTION PBMAIN AS LONG
      LOCAL hDlg,hGrid AS DWORD,ROW,COL,rows,cols AS LONG
      DIM gsArray(0,2) AS STRING
      MLG_INIT
      DIALOG NEW PIXELS,0, "Example",600,200,600,600, %WS_OVERLAPPEDWINDOW TO hDlg
      CONTROL ADD BUTTON,hDlg,%Button,"AddRows",10,0,50,20
      CONTROL ADD "MYLITTLEGRID", hDlg, %Grid, "MYLITTLEGRID", 0, 30, 490,490, %MLG_STYLE OR %WS_TABSTOP
      CONTROL HANDLE hDlg, %Grid TO ghGrid
      ghDlg = hDlg
      DIALOG SHOW MODAL hDlg, CALL MyCallBack
    END FUNCTION
    
    CALLBACK FUNCTION MyCallBack() AS LONG
     SELECT CASE AS LONG CB.MSG
      'CASE %WM_PAINT                                'remarked out and still refreshes with MLG_PutEx ghGrid,gsArray(),-4,0
      '  CONTROL REDRAW CBHNDL,%Grid1
      CASE %WM_INITDIALOG
        FillGrid
      CASE %WM_COMMAND
       SELECT CASE AS LONG CB.CTL
        CASE %Button
         IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
          FillGrid
         END IF
       END SELECT
     END SELECT
    END FUNCTION
    
    SUB FillGrid  'increase  rows by 1 each time this is called
     LOCAL ROW,COL,rows,cols AS LONG
     cols = 2
     rows = UBOUND(gsArray) + 1
     REDIM gsArray(1 TO rows,cols) AS STRING
    
     FOR ROW = 1 TO rows
      FOR COL = 1 TO cols
       INCR gcounter
       gsArray(ROW,COL) = USING$("#",gCounter)
      NEXT
     NEXT
    MLG_PutEx ghGrid,gsArray(),-4,0
     SendMessage(ghGrid,%MLG_SetTopRow,rows-20,0)  'also works fine if rows less than 20 in testing
    END SUB

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hello Mike,

    I used the following snippets to achieve what I wanted. Am I looking for trouble doing this? Works alright though.

    Code:
    Case %WM_PAINT 
        FillGrid ' Read the all records to the gird
        Control Redraw ghDlg&, %IDC_MLGGRID   
        hDC = BeginPaint(ghDlg&, pPaint)
              SendMessage hGrid1,%MLG_REFRESH,0,0
        EndPaint ghDlg&, pPaint
        Function = 1
        Exit Function

    Leave a comment:


  • Mike Doty
    replied

    MLG_ArrayRedim ghGrid,rows,cols,rows,cols sArray() could be from any file.
    'write to grid and refresh
    MLG_PutEx ghGrid,sArray(),-4,1
    CONTROL SET FOCUS ghDlg,%Grid1 'optional

    Triple check that the hDlg and hGrid are not 0 when the call is made?

    MLG_Put hGrid,row,col,VARPTR(s),refresh,sheet 'The sheet parameter is optional

    Leave a comment:


  • Fredrick Ughimi
    replied
    Probably I did not explain my scenario better. I am filling the grid table from a different form other than the grid form. The grid form just sits there waiting for updates from the its table and reads it updating its content. I don't want to close and re-open the grid form to load the current records. I thought that is what the Refresh or Redraw is all about.

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hi Mike,

    Good news. Check out MLG_PUTEX with op of -4
    This code will display any SQLitening sql statement in MLG with automatic column names
    Thanks for pointing this out.

    Leave a comment:


  • Mike Doty
    replied
    Good news. Check out MLG_PUTEX with op of -4

    This code will display any SQLitening sql statement in MLG with automatic column names
    Clicking Test button will ask for a SQL statement

    Didn't add resizing code which would make this great
    Add grid to a portion of a form or create another form with the grid and pop-up.

    The grid on the screen is from the database "sample.db3" that comes with SQLitening containing 10,000 rows.


    Click image for larger version  Name:	fred1.png Views:	1 Size:	13.6 KB ID:	775540
    Code:
    #PBFORMS CREATED V2.01
    #COMPILE EXE
    #DIM ALL
    GLOBAL ghDlg,ghGrid AS DWORD,gSQL AS STRING
    %Grid1 = 1000
    #PBFORMS BEGIN INCLUDES
    %USEMACROS = 1
    #INCLUDE ONCE "WIN32API.INC"
    #PBFORMS END INCLUDES
    #INCLUDE ONCE "mlg.inc"
    #INCLUDE ONCE "sqlitening.inc"
    #PBFORMS BEGIN CONSTANTS
    %Grid1       = 1000
    %BTN_BUTTON1 = 1001
    #PBFORMS END CONSTANTS
    #PBFORMS DECLARATIONS
    FUNCTION PBMAIN()
      gSql = "select rowid,* from parts" 'default sql statement
      slOpen "sample.db3"
      MLG_INIT
      ShowDialog1 0
    END FUNCTION
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
      SELECT CASE AS LONG CB.MSG
          CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CB.WPARAM THEN
            ' Save control focus
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            ' Restore control focus
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
    
        CASE %WM_INITDIALOG
          FillGrid
        CASE %WM_COMMAND
          ' Process control notifications
          SELECT CASE AS LONG CB.CTL
            CASE %BTN_BUTTON1
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                STATIC sql AS STRING
                gSql = INPUTBOX$("prompt","Title",gSql)
                FillGrid
              END IF
    
            CASE %Grid1
    
          END SELECT
      END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
      LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
      LOCAL hDlg  AS DWORD
    
      DIALOG NEW hParent, "MLG/SQLitening", ,, 730, 350, %WS_POPUP OR %WS_BORDER _
        OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
        %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _
        %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
        %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    
      CONTROL ADD "MYLITTLEGRID", hDlg, %Grid1, "MYLITTLEGRID", 20, 0, 700, 300, %MLG_STYLE
      CONTROL ADD BUTTON, hDlg, %BTN_BUTTON1, "Test", 15, 320, 50, 13
    #PBFORMS END DIALOG
      ghDlg = hDlg
      CONTROL HANDLE ghDlg, %Grid1 TO ghGrid
      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
      FUNCTION = lRslt
    END FUNCTION
    
    FUNCTION FillGrid AS LONG
     DIM sArray() AS STRING
     LOCAL s AS STRING
     LOCAL cols,rows,ROW,COL AS LONG
    
     'Select records from SQLitening
     IF LEN(gSQL) = 0 THEN EXIT FUNCTION
     slSelAry gSql,sArray(),"E0"
     IF slGetErrorNumber THEN ? slGetError,,FUNCNAME$:EXIT FUNCTION
    
     cols = UBOUND(sArray,1)
     rows = UBOUND(sArray,2)
     IF rows < 1 THEN ? "No data",,FUNCNAME$:EXIT FUNCTION
     DIALOG SET TEXT ghDlg,gSql
    
     'size grid and set column names
     MLG_ArrayRedim ghGrid,rows,cols,rows,cols 'so column names fit first time
     s="" 'column names in row 0
     FOR COL = 1 TO cols
      s+= USING$("&_,",sArray(COL,0))
     NEXT
     s = LEFT$(s,-1)
     MLG_FormatColTitles ghgrid,s
    
     'Create second array in row,col order for MLG
     DIM sArray2(rows,cols) AS STRING
     FOR ROW = 1 TO rows
      FOR COL = 1 TO cols
       sArray2(ROW,COL) = sArray(COL,ROW)
      NEXT
     NEXT
     'write to grid
     MLG_PutEx ghGrid,sArray2(),-4,0
     CONTROL SET FOCUS ghDlg,%Grid1
    END FUNCTION
    Last edited by Mike Doty; 12 Oct 2018, 08:45 PM.

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hi Mike,

    Here is a snippet.

    Code:
    GLOBAL hBillingPatientsGrid AS DWORD
    
    METHOD BrowseBillingPatientsRecords(BYVAL nCbHndl AS LONG) AS LONG
    
                DIM sArray() AS STRING
                LOCAL cols,rows,op,refresh,x,ROW,COL AS LONG
                LOCAL COUNT AS LONG
                LOCAL myrow  AS LONG
                LOCAL mycol  AS LONG
    
                op = 2
                refresh = 1
    
                MLG_Init
                CONTROL HANDLE nCbHndl, %ID_FRMBROWSEBILLINGPATIENTSWAITING_USERCONTROL1 TO hBillingPatientsGrid
                MLG_FormatColTitles hBillingPatientsGrid,"RecNo,SNo,HNo,Surname,Othernames,Category,TimeSent,Doctor,SentBy,Clinic/Section,Locked,Default"
    
                 'Set column width
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 1, 1
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 2, 100
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 3, 120
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 4, 200
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 5, 200
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 6, 150
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 7, 200
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 8, 200
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 9, 200
                 SendMessage hBillingPatientsGrid, %MLG_SETCOLWIDTH, 10, 200
    
                 'sort
                 SendMessage hBillingPatientsGrid, %MLG_SORT, %MLG_ASCEND , 4
    
                 'Set grid color
                 GI.CellBkColorRGB=RGB(255,255,200)
                 GI.WindowBkColorRGB=RGB(255,200,150)
                 SendMessage hBillingPatientsGrid, %MLG_SETGRIDEXSTYLE, VARPTR(GI), 0
                 FOR COUNT=2 TO 24 STEP 2
                     MLG_FormatRowHighLight hBillingPatientsGrid,COUNT,%MLG_HILITE
                 NEXT COUNT
    
               'Load Records
               slSelAry "SELECT RowID as RecordNo, * from tblBillingAwaiting ORDER BY TimeSent",sArray()
               cols = UBOUND(sArray(1))
               rows = UBOUND(sArray(2))
               IF cols < 0 THEN BEEP:EXIT METHOD
                  DIM sArray2(rows,cols) AS STRING     'move data to another array
                  FOR ROW = 0 TO rows
                    FOR COL = 1 TO cols
                     sArray2(ROW,COL) = sArray(COL,ROW)
                    NEXT
                  NEXT
    
                  MLG_ArrayRedim hBillingPatientsGrid,rows,cols,rows,cols
                  MLG_PutEx hBillingPatientsGrid,sArray2(),op,refresh
                  SendMessage hBillingPatientsGrid,%MLG_REFRESH,0,0
    
          END METHOD
    
       'Notifications
       SELECT CASE nCbMsg
        CASE %WM_INITDIALOG
              PatientsAwaiting.BrowseBillingPatientsRecords(nCbHndl)
    
              CASE %WM_PAINT
                CONTROL REDRAW nCbHndl, %ID_FRMBROWSEBILLINGPATIENTSWAITING_USERCONTROL1
    
    '            hDC = BeginPaint(nCbHndl, pPaint)
    '                 SendMessage hNursesPatientsGrid,%MLG_REFRESH,0,0
    '            EndPaint nCbHndl, pPaint
    '            Function = 1
    '            Exit Function
    
           CASE %WM_NOTIFY
               MLGN=nCbLparam
                IF @MLGN.NMHeader.idFrom = %ID_FRMBROWSEBILLINGPATIENTSWAITING_USERCONTROL1 THEN
                 SELECT CASE @MLGN.NMHeader.Code
                     CASE %MLGN_ROWSELCHANGE  'sent after buttonup if whole row/rows selected
                       [email protected] 'current row
                       sRecordNo = MLG_Get(hBillingPatientsGrid, myrow,1)
                          slSEL "SELECT RowID as RecordNo, * FROM tblBillingAwaiting WHERE RecordNo  = '" + sRecordNo + "'"
                       IF ISTRUE slGetRow THEN
                          VD_Text(nCbHndl, %ID_FRMBROWSEBILLINGPATIENTSWAITING_TXTRECORDNO, slFN("RecordNo"))
                       END IF
                       slCloseSet
    
                   END SELECT
    
                END IF
    
    END SELECT
    Last edited by Fredrick Ughimi; 12 Oct 2018, 06:51 PM.

    Leave a comment:


  • Mike Doty
    replied
    Need to see some code.
    Last edited by Mike Doty; 12 Oct 2018, 07:33 AM.

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hello Mike,

    Thank you for your response.

    I have found a way to save MLG row to SQLitening table. Infact you provided provided the solution here in one of your posts.

    Now I have found out that the MLG don't refresh its contents when records are entered into its corresponding SQLitening table. I have tried PB's Control Redraw... and MLG's SendMessage hGrid Refresh.... Nothing seems to work.

    Best regards.

    Leave a comment:


  • Mike Doty
    replied
    Thank you for responding. I understand that. Doing that would be very
    tedious for what I want to achieve. I want to be able to select through rows and
    have its contexts displayed on textboxes dynamically. Maybe this is not a Grid thing?

    I do that all the time with Listview. I do that mostly for the purpose of editing
    and saving back changes to the database through the textboxes. I guess
    I don't have to do that anymore with the Grid control. Users can edit the cells of a
    row directly on the grid and then save back to the database.

    Saving a row to the database is now something I need to find out.
    Sounds like you were doing it right

    Listview, listbox are great for viewing, sorting, grouping and selecting.
    By trying to do everything in a listview or grid doesn't eliminate the need for all
    validation checks and formatting input still needs to be checked.

    Maybe look at a second control with the list or grid control:
    PickList, Property grid, combobox or text boxes like you were doing.
    The edit control could popup, stay on screen or be text boxes..

    Two controls is much easier to program and control than trying to work on a single grid line.





    Leave a comment:


  • Fredrick Ughimi
    replied
    Thank you, Gary.

    Leave a comment:


  • Gary Beene
    replied
    Hello, Fred!

    Yes, with the grid, users would edit the row/cell content in place. Then, there is a Save function that saves all rows and columns at one time (a sheet at a time).

    See the "Save and Load" section of Help for details.

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hello Gary,

    Thank you for responding. I understand that. Doing that would be very
    tedious for what I want to achieve. I want to be able to select through rows and
    have its contexts displayed on textboxes dynamically. Maybe this is not a Grid thing?

    I do that all the time with Listview. I do that mostly for the purpose of editing
    and saving back changes to the database through the textboxes. I guess
    I don't have to do that anymore with the Grid control. Users can edit the cells of a
    row directly on the grid and then save back to the database.

    Saving a row to the database is now something I need to find out.

    Best regards.


    Leave a comment:


  • Gary Beene
    replied
    Howdy, Fred!

    To get the text in a cell ... from the "Function Reference" section of MLG Help ...

    Code:
    Buffer$ = MLG_Get(hGrid, Row, Col)
    Control Set Text hDlg, %IDC_TextBox, Buffer$

    Leave a comment:


  • Fredrick Ughimi
    replied
    Hello,

    I am just trying for the first time to use MLG in real project.

    A while ago my development system crashed and I was able to recover most of the
    project file. But I lost almost the codes I wrote on using MLG with SQLitening.
    I can't seems to remember how I figured out how (with the help Mike Doty) to dynamically
    read the cell contents of MLG into individual Textboxes.

    Any pointers or sample codes would be much appreciated.

    Best regards.

    Leave a comment:


  • janne sikstrom
    replied
    Whoto mirror switch h(x)

    How do I delete the row and column header of the middle sheet in MLG workbook, when I have for example three sheets?
    I can’t finds message correspondence to switch h(x)

    In the example with graphics, it works with :
    Probably advisable to hide the headers
    SendMessage hGrid1 ,%MLG_SETCOLWIDTH ,0,0
    SendMessage hGrid1 ,%MLG_SETROWHEIGHT ,0,0

    Have tried different variations, can remove the row header but in the column header will be left a few pixels on top.

    Any suggestions?

    Leave a comment:


  • janne sikstrom
    replied
    - "By the way, Gary Beene now owns MLG."
    Then I understand.
    Then we direct the question to Garry, Previously the source code was included for the MLG, is the source code to MLGPrint.dll available somewhere?

    Grateful for answers in any direction.

    PS! Like the new look

    Leave a comment:


  • james klutho
    replied
    Try the helper function

    MLG_FormatGridex(hGrid,%RGB_POWDERBLUE,0,0,0,0,0,0,0,0)

    That should be what you want. By the way, Gary Beene now owns MLG. I don't plan to visit much anymore. Jim

    Leave a comment:

Working...
X