Announcement

Collapse
No announcement yet.

Listbox Get Select problem

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

  • Listbox Get Select problem

    I am using PBWin9.0.1 and DDT. I am trying to print selected items from a multiple selection list box, using Listbox Get Select and Listbox Get Text.
    The only way I can make it work is the code below. I have to unselect each item as I go, so Listbox Get Select can get the next selected item index number.
    I would think there would be a better way.
    Any help and explanation would be appreciated.

    John Tate

    Code:
    SUB printSelections(hDlg AS DWORD)
        OPEN "selected.txt" FOR OUTPUT AS #9
    LOCAL I,numselected,index,mx AS LONG
    LOCAL tempvar AS STRING
    LISTBOX GET SELCOUNT hDlg,%idc_listbox7 TO numselected
    
    FOR I = 1 TO numselected
        LISTBOX GET SELECT hDlg,%idc_listbox7 TO index
        LISTBOX GET TEXT hDlg,%idc_listbox7 ,index TO tempvar
        PRINT #9,tempvar
        LISTBOX UNSELECT hDlg,%idc_listbox7,index
        NEXT
        CLOSE 9
        DLLPRINT hDlg,"selected.txt,,,/PP"
    END SUB
    Last edited by John Tate; 13 Mar 2009, 11:47 PM.

  • #2
    Code:
    itemno = 1
    FOR I = 1 TO numselected
        LISTBOX GET SELECT hDlg,%idc_listbox7,itemno TO index
        IF index = 0 THE EXIT FOR
        LISTBOX GET TEXT hDlg,%idc_listbox7 ,index TO tempvar
        PRINT #9,tempvar
        itemno = index + 1
    NEXT
    The helpfile says:
    The LISTBOX is searched to find the first selected item. If the item& parameter is included, searching starts at that position to facilitate retrieving multiple selected items. If item& is omitted, the search starts at the first data item. The index number of the selected item is assigned to the variable designated by datav&. If no item is selected, the value zero (0) is assigned to it.
    So you want to increment the starting itemno to be then next item after your last found index item. And test for a zero return to bail out.
    Rick Angell

    Comment


    • #3
      Code:
      #COMPILE EXE
      #INCLUDE "win32api.inc"
      
      FUNCTION PBMAIN () AS LONG
      
          DIALOG NEW PIXELS, 0,"Listbox Getter",,,600,480, %WS_SYSMENU OR %WS_MINIMIZEBOX TO hDlg???
          
          DIM x$(1 TO 99)
          FOR l%=1 TO 99
              x$(l%)="Item "+FORMAT$(l%)
          NEXT l%
          
          CONTROL ADD LISTBOX, hDlg???,101, x$(), 10, 10, 580, 400, %LBS_MULTIPLESEL OR %LBS_NOTIFY OR %WS_TABSTOP OR %WS_VSCROLL
          CONTROL ADD BUTTON, hDlg???,102,"Show Selected Items", 10, 440, 580, 24 CALL ShowSelectedItems
          
          DIALOG SHOW MODAL hDlg???
          
      END FUNCTION
      
      CALLBACK FUNCTION ShowSelectedItems
      
          LISTBOX GET SELCOUNT CB.HNDL, 101 TO scount&
          msg$ = "There are "+FORMAT$(scount&)+" item(s) selected:"+$CRLF+$CRLF
          r&=0
          FOR l%=1 TO scount&
              LISTBOX GET SELECT CB.HNDL, 101, r&+1 TO r&
              LISTBOX GET TEXT CB.HNDL, 101, r& TO x$
              msg$ = msg$ + x$ + $CRLF
          NEXT l%
          MSGBOX msg$
      END FUNCTION

      Comment


      • #4
        Thanks, both of you. I get it now. I was not reading the help file clearly enough to understand it! I think I spent too many hours at the keyboard today!

        In the code below, I get the position of the first selected record. I do not have to start with item 1 position in the listbox.

        Code:
            LISTBOX GET SELECT hDlg,%idc_listbox7 TO index 
            itemno = index
        FOR I = 1 TO numselected
            LISTBOX GET SELECT hDlg,%idc_listbox7,itemno TO index
            IF index = 0 THEN EXIT FOR
            LISTBOX GET TEXT hDlg,%idc_listbox7 ,index TO tempvar
            PRINT #9,tempvar
            itemno = index + 1
            NEXT
        Thanks again,
        John Tate

        Comment

        Working...
        X