Results 1 to 3 of 3

Thread: ListBox control multi selection

  1. #1

    Question ListBox control multi selection

    Ciao,

    a listbox can have multi selection,
    the gettext command only return the first selected line. How do you get the whole list of the selected items ?
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi DirectuX,

    it is solution mostly by Win32API, but seems to work:
    function GetSelectedListboxItems(hDlg as dword, hCtl as long, byref out_result() as string) as long
      long selectionCount
      long hList
      
      control handle hDlg, hCtl to hList
      selectionCount = SendMessage(hList, %LB_GETSELCOUNT, 0, 0)
      
      if selectionCount > 0 then
        long itemIndexes(selectionCount)
        SendMessage(hList, %LB_GETSELITEMS, selectionCount, varptr(itemIndexes(1)))
         
        ' Fit the output array to selection count
        redim out_result(selectionCount)
         
        ' Limited to 512 characters, feel free to adjust
        dim singleTextItem as asciiz * 512 
        
        ' Extract all items from ListBox
        for i as long = 1 to selectionCount
          SendMessage(hList, %LB_GETTEXT, itemIndexes(i), varptr(singleTextItem))
    
    
          out_result(i) = singleTextItem
        next
        
        return selectionCount
      end if
    end function
    
    You can use it like:
    string items()
    long selectedCount = GetSelectedListboxItems(hDlg, %myListBox, items)
    if selectedCount then msgbox hDlg, join$(items, ",")
    

    Petr
    Last edited by Petr Schreiber; 13-02-2020 at 21:58.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Thumbs up

    I didn't get used to sendmessage, now I better understand its meaning.
    Before your sample, I thought there must have been a single command rather than a succession.

    That was instructive to me, thanks Petr !
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. Control Listbox - why does it always crash?
    By ReneMiner in forum UI (User Interface)
    Replies: 14
    Last Post: 10-11-2012, 20:04
  2. multi dialog modeless
    By Lionheart008 in forum UI (User Interface)
    Replies: 6
    Last Post: 07-01-2010, 19:40
  3. CMS selection
    By ErosOlmi in forum General
    Replies: 2
    Last Post: 09-02-2006, 17:35

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •