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. How to change a string in a combo box

How to change a string in a combo box

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasejsontutorial
3 Posts 2 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.
  • S Offline
    S Offline
    Sprudling
    wrote on last edited by
    #1

    I have a regular combobox, and I want the selected item (the item shown in the editbox area of the combobox) to be automatically updated when I write something in another editbox. I also want this string to be "stored", so that next time I pull down the combobox this string is still there. So just manipulating the editbox itself isn't good enough. I also want the index to not change. I'm not using MFC, just plain Win32 API stuff. I hope you understand what I mean :] Sprudling :confused:

    P 1 Reply Last reply
    0
    • S Sprudling

      I have a regular combobox, and I want the selected item (the item shown in the editbox area of the combobox) to be automatically updated when I write something in another editbox. I also want this string to be "stored", so that next time I pull down the combobox this string is still there. So just manipulating the editbox itself isn't good enough. I also want the index to not change. I'm not using MFC, just plain Win32 API stuff. I hope you understand what I mean :] Sprudling :confused:

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      1. Get the index of the item that is in the edit area of your combo box with the CB_GETCURSEL message. 2. Remove this index from the combo box. That will remove this string completely. Use the CB_DELETESTRING message. 3. Get the text from your external edit box, probably with the WM_GETTEXT message. 4. Insert the new text string at the same index of the original string with the CB_INSERTSTRING message. One more good tip it to send a WM_SETREDRAW message with false in the WPARAM field, before you even start removing and inserting the strings in the combo box, because this will make it so that the combo box does not redraw itself while you are manipulating the data. When you are done, send a WM_SETREDRAW message with TRUE in the WPARAM field, and this will force the combo box to repaint with all of the new data.

      S 1 Reply Last reply
      0
      • P Paul M Watt

        1. Get the index of the item that is in the edit area of your combo box with the CB_GETCURSEL message. 2. Remove this index from the combo box. That will remove this string completely. Use the CB_DELETESTRING message. 3. Get the text from your external edit box, probably with the WM_GETTEXT message. 4. Insert the new text string at the same index of the original string with the CB_INSERTSTRING message. One more good tip it to send a WM_SETREDRAW message with false in the WPARAM field, before you even start removing and inserting the strings in the combo box, because this will make it so that the combo box does not redraw itself while you are manipulating the data. When you are done, send a WM_SETREDRAW message with TRUE in the WPARAM field, and this will force the combo box to repaint with all of the new data.

        S Offline
        S Offline
        Sprudling
        wrote on last edited by
        #3

        Thanks, it worked :) At least when I sent a CB_SETCURSEL message with the index to the combobox afterwards. And thanks for the WM_SETREDRAW thing too :) Sprudling

        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