Announcement

Collapse
No announcement yet.

General purpose listbox

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

  • General purpose listbox

    Code:
    'General purpose list box
    'Read any number of items  Add/Delete/Replace/Sort
    '
    '1  Added %WS_VSCROLL, but doesn't scroll?
    '2  How are items added         to a listbox?
    '3  How are items deleted from     a listbox?
    '4  How are items replaced      in a listbox?
    '5  How are items sorted        in a listbox?
    'Any help filling in the empty subroutines would be appreciated
    'Trying to eliminate ever having to change code in the callbacks
    
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.INC"
    '
    GLOBAL g_Result1&, g_Result2&, g_hDlg&, g_a$()
    '
    SUB FillGlobalArray(MaxItem AS LONG)
      LOCAL Temp&
      DIM g_a$(1:MaxItem)                'Read disk data normally here
      FOR temp& = 1 TO MaxItem
        g_a$(temp&) = "Item " + FORMAT$(temp&)
       NEXT x&
    END SUB
    '
    CALLBACK FUNCTION BtnCallback
    
        IF CBCTL = %IDOK THEN
            CONTROL SEND CBHNDL, 100, %LB_GETCURSEL, 0, 0 TO g_Result1&
            IF g_Result1& >= 0 THEN
                'CONTROL SEND CBHNDL, 100, %LB_GETCOUNT, 0, 0 TO Result2&
                INCR g_Result1
                'MessageBox CBHNDL, "Item " + FORMAT$(Result1& + 1) + " of " + FORMAT$(Result2&) + " selected!", "Test", %MB_OK
            END IF
            DIALOG END CBHNDL, 1
        ELSE
            DIALOG END CBHNDL, 0
        END IF
    END FUNCTION
    '
    CALLBACK FUNCTION DlgCallback
        ' Handle double click messages by pushing the OK button
        IF CBCTL = 100 AND CBCTLMSG = %LBN_DBLCLK THEN
            CONTROL SEND CBHNDL, %IDOK, %BM_CLICK, 0, 0
        END IF
    END FUNCTION
    '
    SUB ListBoxCreate
     DIALOG NEW 0,"From Lance ListBox Example",,,190,180,%WS_SYSMENU OR %WS_THICKFRAME OR %DS_CENTER OR %WS_VSCROLL, TO g_hDlg
     CONTROL ADD BUTTON, g_hDlg, %IDOK, "&Ok", 10,150,70,14, %BS_DEFAULT OR %WS_TABSTOP CALL BtnCallback
     CONTROL ADD BUTTON, g_hDlg, %IDCANCEL, "&Cancel", 100,150,70,14 CALL BtnCallback
     CONTROL ADD LISTBOX, g_hDlg, 100, g_a$(), 10, 10, 160, 126, %LBS_DisableNoScroll OR %WS_TABSTOP OR %LBS_NOTIFY, %WS_EX_CLIENTEDGE
     DIALOG SHOW MODAL g_hDlg CALL DlgCallback
    END SUB
    '
    'Empty Subroutines Here   ................................................
    '
    SUB ListBoxAdd(Item$)
    END SUB
    '
    SUB ListBoxDelete(ItemNumber&)
    END SUB
    '
    SUB ListBoxReplace(ItemNumber&,Item$)
    END SUB
    '
    SUB ListBoxSort
    END SUB
    '.........................................................................
    
    FUNCTION PBMAIN()AS LONG
      DIM ItemNumber&, Item$
      CALL FillGlobalArray(500)  'Fill g_a$() with data
      CALL ListBoxCreate       'Use g_a$() data
      IF g_Result1>0 THEN MSGBOX g_a$(g_Result1)+ " picked"
      '
      'Appreciate help with any of these empty subroutines
      ' CALL ListBoxAdd(Item$)
      ' CALL ListBoxDelete(ItemNumber&)
      ' CALL ListBoxReplace(ItemNumber&,Item$)
      ' CALL ListBoxSort
    END FUNCTION
    ------------------




    [This message has been edited by Mike Doty (edited March 09, 2001).]
    How long is an idea? Write it down.

  • #2
    Mike,

    If your listbox is on a MODAL dialog, you will not be able to do
    it the way your code sample is structured.

    Have you looked at the DDT LISTBOX statments?

    LISTBOX ADD
    LISTBOX DELETE

    Listboxes can be set (initialized, created, etc.) with the
    %LBS_SORT style if desired.



    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

    Comment


    • #3
      mike;

      some excellent weekend "listbox" reading, courtesy of borje hagsten...

      http://www.powerbasic.com/support/pb...ad.php?t=22871
      http://www.powerbasic.com/support/pb...ad.php?t=22872
      http://www.powerbasic.com/support/pb...ad.php?t=22873
      http://www.powerbasic.com/support/pb...ad.php?t=22875

      hth
      regards,
      jules
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        Jules,
        Thank you for pointing me to the code.
        It is exactly what I was trying to do.
        Borje's Virtual Listbox will create/insert/delete and
        replace unlimited items in a listbox.
        Great work!


        [This message has been edited by Mike Doty (edited March 09, 2001).]
        How long is an idea? Write it down.

        Comment

        Working...
        X