Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sorting Strings In a ListBox win32

Sorting Strings In a ListBox win32

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 457225
    wrote on last edited by
    #1

    I am wondering, since u can pass a style LBS_SORT to the listbox when Initalized. But is there a flag that I can pass to SetDlgItemMessage(...) to sort the LB when I push a button ??? I dont want to have to write my own Sorting function to sort strings Alphabetically. Thanks

    L B M 5 Replies Last reply
    0
    • M Member 457225

      I am wondering, since u can pass a style LBS_SORT to the listbox when Initalized. But is there a flag that I can pass to SetDlgItemMessage(...) to sort the LB when I push a button ??? I dont want to have to write my own Sorting function to sort strings Alphabetically. Thanks

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      if u set the style it will insert new items in a sorted order so why would u want to sort it urself?


      "there is no spoon"
      biz stuff   about me

      1 Reply Last reply
      0
      • M Member 457225

        I am wondering, since u can pass a style LBS_SORT to the listbox when Initalized. But is there a flag that I can pass to SetDlgItemMessage(...) to sort the LB when I push a button ??? I dont want to have to write my own Sorting function to sort strings Alphabetically. Thanks

        B Offline
        B Offline
        Big Art
        wrote on last edited by
        #3

        I think what you want is to change the sorting style of the listbox at runtime. Try SetWindowLong(..) in your button handler. Art

        M 1 Reply Last reply
        0
        • B Big Art

          I think what you want is to change the sorting style of the listbox at runtime. Try SetWindowLong(..) in your button handler. Art

          M Offline
          M Offline
          Member 457225
          wrote on last edited by
          #4

          Exactly thats what I was trying to do at runtime sort the items in the LB.I will try SetWindowsLong(...)

          1 Reply Last reply
          0
          • M Member 457225

            I am wondering, since u can pass a style LBS_SORT to the listbox when Initalized. But is there a flag that I can pass to SetDlgItemMessage(...) to sort the LB when I push a button ??? I dont want to have to write my own Sorting function to sort strings Alphabetically. Thanks

            M Offline
            M Offline
            Member 457225
            wrote on last edited by
            #5

            You can not use SetWindowLong(...)for a list box, causes the program to freeze.

            B 1 Reply Last reply
            0
            • M Member 457225

              You can not use SetWindowLong(...)for a list box, causes the program to freeze.

              B Offline
              B Offline
              Big Art
              wrote on last edited by
              #6

              Don't know why you are getting that. Here is my code: ---------------------------------- DWORD dwStyle = m_lb1.GetStyle(); dwStyle |= LBS_SORT; ::SetWindowLong(m_lb1.GetSafeHwnd(),GWL_STYLE,dwStyle); ----------------------------------- A check with spy++ clearly shows the listbox style has changed from no sort to sort. However the sorting operation doesn't occur. Don't know why. Sorry. It doesn't freeze the app though. Art

              1 Reply Last reply
              0
              • M Member 457225

                I am wondering, since u can pass a style LBS_SORT to the listbox when Initalized. But is there a flag that I can pass to SetDlgItemMessage(...) to sort the LB when I push a button ??? I dont want to have to write my own Sorting function to sort strings Alphabetically. Thanks

                B Offline
                B Offline
                Big Art
                wrote on last edited by
                #7

                Read this: http://www.codeproject.com/combobox/recreatelistbox.asp Art

                M 1 Reply Last reply
                0
                • B Big Art

                  Read this: http://www.codeproject.com/combobox/recreatelistbox.asp Art

                  M Offline
                  M Offline
                  Member 457225
                  wrote on last edited by
                  #8

                  Mine does not work either this is my code ------------------------------------------------------- int x = SetWindowLong(dhwnd,GWL_STYLE,GetWindowLong(dhwnd,GWL_STYLE)|LBS_SORT); SendDlgItemMessage(dhwnd,IDC_LIST1,LB_RESETCONTENT,0,0); for(int i=0; i<6; ++i) SendDlgItemMessage(dhwnd,IDC_LIST1,LB_ADDSTRING,0,(LPARAM)table[i].list); SendDlgItemMessage(dhwnd,IDC_LIST1,LB_SETCURSEL,0,0); SetDlgItemText(dhwnd,IDC_EDIT1,table[0].list); ------------------------------------------------------------------------- I dont think I am getting the handle to the listbox

                  1 Reply Last reply
                  0
                  • M Member 457225

                    I am wondering, since u can pass a style LBS_SORT to the listbox when Initalized. But is there a flag that I can pass to SetDlgItemMessage(...) to sort the LB when I push a button ??? I dont want to have to write my own Sorting function to sort strings Alphabetically. Thanks

                    M Offline
                    M Offline
                    Member 457225
                    wrote on last edited by
                    #9

                    I have not explained this very. I created a listbox using the resource editor. The problem is I cant set the style to a LB because the resource editor set all the flags. But I assume u can change the style using SetWindowLong(...) but nothing happens. Is there a way I can get a handle to the listbox. This is win32 and not MFC.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups