Announcement

Collapse
No announcement yet.

Listbox - change text?

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

  • Listbox - change text?

    Does anyone know how to MODIFY the text of an item in a listbox? (As opposed to adding a new one)
    In VB i would go Listbox1.ListItems(index).Text = "newtext"

    For example, the following code displays a listbox with 5 entries... is it possible to have it so that if i click on a list item, a "+" will be added to the front of it's text?

    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "win32api.inc"
       %ID_LISTBOX = 101
       Function PbMain
          Dim hDlg As Long, i As Long
          Dialog New 0, "Test", , , 150, 120, %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX To hDlg
          Control Add ListBox, hDlg, %ID_ListBox, , 10, 10,  130,  100, _
             %WS_TABSTOP Or %WS_HSCROLL Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
          For i = 1 To 5
            ListBox Add hDlg, %ID_LISTBOX, "Item " & STR$(I)
          Next
          Control Send hdlg, %ID_ListBox, %LB_SETHORIZONTALEXTENT, 350, 0
          Dialog Show Modal hDlg
       End Function

    ------------------
    -

  • #2
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "win32api.inc"
       %ID_LISTBOX = 101
       
       Sub ChangeLbString (hDlg As Long, Id As Long, Idx As Long, Txt As String)
          Control Send hdlg, Id, %LB_DELETESTRING, Idx - 1, 0
          Control Send hdlg, Id, %LB_INSERTSTRING, Idx - 1, StrPtr(Txt)
       End Sub
       
       Function PbMain
          Dim hDlg As Long, i As Long
          Dialog New 0, "Test", , , 150, 120, %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX To hDlg
          Control Add ListBox, hDlg, %ID_ListBox, , 10, 10,  130,  100, _
             %WS_TABSTOP Or %WS_HSCROLL Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
          For i = 1 To 10
            ListBox Add hDlg, %ID_LISTBOX, "Item " & Str$(I)
          Next
    
          ChangeLbString hDlg, %ID_ListBox, 3, "Semen"
          ChangeLbString hDlg, %ID_ListBox, 7, "Wayne"
    
          Control Send hdlg, %ID_ListBox, %LB_SETHORIZONTALEXTENT, 350, 0
          Dialog Show Modal hDlg
       End Function

    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      Too easy! A million thanks Semen - I searched the forums and POFFS for over two hours last night searching listbox examples, with no go!
      I can resume programming now


      ------------------
      -

      Comment


      • #4
        I notice you did the Dialog Show after insetring the new text.
        Is this required?
        I have been trying to get this working in my app for 4 Hrs today.
        Even went for a complete refill of the listbox so I could keep
        working in other areas till I found the fix.
        I think maybe it has to do with the text being refrenced by pointer
        I made additional variables local to the function and used msgbox
        tests to verify the correct data is there but still I get no
        change of the text in the list box.

        I find it very frusterating that there are so many messages
        not listed in the PB help file, and that the help file
        gives the impression that messages it does list are all there is.

        Maybe it's just me.

        Anyway I would appreciate any help I get. Source code is not
        attached as it is running over 800 lines now and a rather large
        inventory CSV file is also being used.

        If you can help I will email the file to you.
        [email protected]
        or AIM FloridaDingo2001

        Lane Weast

        ------------------

        Comment


        • #5
          This kinda goes back to a previous post I made about modifying the existing text in a listbox
          My app would be watching MSIE and putting it's ADDRESS bar text into the listbox and modifying it every 1.5 seconds...if it changes that is...
          People told me it could not be done and that I had to remove/re-insert....

          After the dialog is shown can this method stil be used?

          ------------------
          Scott
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            I ran a test of changing an entry after the Dialog is shown.
            It works fine.

            Still dont see why mine doesn't work.
            I have tried the method listed here.
            and Dave's code in the source code section with no success.
            Lane

            #COMPILE EXE
            #REGISTER NONE
            #DIM ALL
            #INCLUDE "win32api.inc"
            %ID_LISTBOX = 101
            %ID_BUTTON1 = 102
            GLOBAL hDlg AS LONG
            SUB ChangeLbString (hDlg AS LONG, Id AS LONG, Idx AS LONG, Txt AS STRING)
            CONTROL SEND hdlg, Id, %LB_DELETESTRING, Idx - 1, 0
            CONTROL SEND hdlg, Id, %LB_INSERTSTRING, Idx - 1, STRPTR(Txt)
            END SUB

            CALLBACK FUNCTION button_hit()

            ChangeLbString hDlg, %ID_ListBox, 4, "Lane"
            END FUNCTION


            FUNCTION PBMAIN
            DIM hDlg AS LONG, i AS LONG
            DIALOG NEW 0, "Test", , , 150, 120, %WS_SYSMENU OR %WS_CAPTION OR %WS_MINIMIZEBOX TO hDlg
            CONTROL ADD LISTBOX, hDlg, %ID_ListBox, , 10, 10, 130, 100, _
            %WS_TABSTOP OR %WS_HSCROLL OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
            CONTROL ADD BUTTON, hDlg, %ID_BUTTON1, "Hit Me", 20, 105, 30, 10,%BS_DEFAULT,, CALL button_hit

            FOR i = 1 TO 10
            LISTBOX ADD hDlg, %ID_LISTBOX, "Item " & STR$(I)
            NEXT

            ChangeLbString hDlg, %ID_ListBox, 3, "Semen"
            ChangeLbString hDlg, %ID_ListBox, 7, "Wayne"

            CONTROL SEND hdlg, %ID_ListBox, %LB_SETHORIZONTALEXTENT, 350, 0
            DIALOG SHOW MODAL hDlg
            END FUNCTION




            ------------------

            Comment


            • #7
              As Homer Simpson would say -- Doohhh!!!!

              I had renamed the sub that creates the text$ for listbox entry
              to more accuratly reflect the subs purpose and then added a new
              sub with the old name.

              I failed to add the renamed sub into the procedure, as a result
              the ChangeLbString routine was working fine but writing the
              exact same data back into the field instead of the changed data.

              A lesson learned (AGAIN!) When you've been working on the same
              problem for so long your eye's are burning take a good long
              break.

              Problem fixed.
              Lane

              ------------------

              Comment

              Working...
              X