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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Add/Remove items in a listBox

Add/Remove items in a listBox

Scheduled Pinned Locked Moved Managed C++/CLI
winformstutorial
7 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.
  • N Offline
    N Offline
    newkid
    wrote on last edited by
    #1

    Hi, i'm using windows forms and I was wondering how to add to a listBox from a comboBox. Also how to remove an item from the listBox. private: System::Void btnConfirmCommand_Click(System::Object^ sender, System::EventArgs^ e) { this->cmbCommands->Select(); this->lstCommands->Items->Add(cmbCommands); } private: System::Void btnRemoveCommand_Click(System::Object^ sender, System::EventArgs^ e) { this->lstCommands->Select(); this->lstCommands->Items->Remove(lstCommands); }

    modified on Thursday, January 31, 2008 10:27:48 AM

    L 1 Reply Last reply
    0
    • N newkid

      Hi, i'm using windows forms and I was wondering how to add to a listBox from a comboBox. Also how to remove an item from the listBox. private: System::Void btnConfirmCommand_Click(System::Object^ sender, System::EventArgs^ e) { this->cmbCommands->Select(); this->lstCommands->Items->Add(cmbCommands); } private: System::Void btnRemoveCommand_Click(System::Object^ sender, System::EventArgs^ e) { this->lstCommands->Select(); this->lstCommands->Items->Remove(lstCommands); }

      modified on Thursday, January 31, 2008 10:27:48 AM

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      newkid wrote:

      this->lstCommands->Items->Add(cmbCommands);

      You need to pass in the actual string you want to add not the ComboBox control.

      led mike

      N 1 Reply Last reply
      0
      • L led mike

        newkid wrote:

        this->lstCommands->Items->Add(cmbCommands);

        You need to pass in the actual string you want to add not the ComboBox control.

        led mike

        N Offline
        N Offline
        newkid
        wrote on last edited by
        #3

        so i create a string say x, how do you set an item in the comboBox to x? string x; this->cmbCommands->Select(); cmbCommands->SelectedItem; this->lstCommands->Items->Add("x");

        L R 2 Replies Last reply
        0
        • N newkid

          so i create a string say x, how do you set an item in the comboBox to x? string x; this->cmbCommands->Select(); cmbCommands->SelectedItem; this->lstCommands->Items->Add("x");

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Are you in school or leaning by working from a book or what? If you are using a book to start out I think you might need a different book, or you may have skipped some stuff or something. This is very very beginner level stuff and you are already on to list boxes and combo boxes without knowing it. That's probably not a good idea.

          led mike

          1 Reply Last reply
          0
          • N newkid

            so i create a string say x, how do you set an item in the comboBox to x? string x; this->cmbCommands->Select(); cmbCommands->SelectedItem; this->lstCommands->Items->Add("x");

            R Offline
            R Offline
            rover_boy
            wrote on last edited by
            #5

            This should solve your problem. //To Add if(cmbCommands->Text->Length > 0) { lstCommands->Items->Add(cmbCommands->Text); } //To remove if(lstCommands->SelectedIndex !=-1) { lstCommands->Items->RemoveAt(lstCommands->SelectedIndex); }

            L N 2 Replies Last reply
            0
            • R rover_boy

              This should solve your problem. //To Add if(cmbCommands->Text->Length > 0) { lstCommands->Items->Add(cmbCommands->Text); } //To remove if(lstCommands->SelectedIndex !=-1) { lstCommands->Items->RemoveAt(lstCommands->SelectedIndex); }

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              rover_boy wrote:

              This should solve your problem.

              Really? It will solve this?

              newkid wrote:

              so i create a string say x, how do you set an item in the comboBox to x? string x; this->lstCommands->Items->Add("x");

              I think not.

              led mike

              1 Reply Last reply
              0
              • R rover_boy

                This should solve your problem. //To Add if(cmbCommands->Text->Length > 0) { lstCommands->Items->Add(cmbCommands->Text); } //To remove if(lstCommands->SelectedIndex !=-1) { lstCommands->Items->RemoveAt(lstCommands->SelectedIndex); }

                N Offline
                N Offline
                newkid
                wrote on last edited by
                #7

                Thanks thats sovled the problem

                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