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#
  4. remove items from Listbox

remove items from Listbox

Scheduled Pinned Locked Moved C#
8 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
    scottichrosaviakosmos
    wrote on last edited by
    #1

    I have 2 listboxs. 1st one is data bound and secound one is populated by selecting 1st. eg: listbox1 jenny rock when i click listbox 1 items it also appear in listbox2. now when i click listbox1 item 2 things happen: 1. listbox2 populates with same item selected in listbox1. 2. a textbox which gets valueid from listbox1 item select. So now, when i try to remove item from listbox2 then itm should be removed from the list and the valueid in textbox related to the item should also be removed. I have tried o do this by selecteditem property of listbox but it didn't work. since listbox1 is data bound but listbox2 is not.

    L 1 Reply Last reply
    0
    • S scottichrosaviakosmos

      I have 2 listboxs. 1st one is data bound and secound one is populated by selecting 1st. eg: listbox1 jenny rock when i click listbox 1 items it also appear in listbox2. now when i click listbox1 item 2 things happen: 1. listbox2 populates with same item selected in listbox1. 2. a textbox which gets valueid from listbox1 item select. So now, when i try to remove item from listbox2 then itm should be removed from the list and the valueid in textbox related to the item should also be removed. I have tried o do this by selecteditem property of listbox but it didn't work. since listbox1 is data bound but listbox2 is not.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Unless I did not correctly understand your question, something like below should work;

      Listbox2.Items[1].Remove(); // deletes "jenny"

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      S 1 Reply Last reply
      0
      • L Lost User

        Unless I did not correctly understand your question, something like below should work;

        Listbox2.Items[1].Remove(); // deletes "jenny"

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

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

        ok, but what about valueid which is populated when i add items in lstbox2 from listbox1. i have a button "ADD". when i select item in listbox1 and click add button item is added to listbox2 and so as its valueid in textbox. but when i click on remove button the item will get removed from listbox2 but valuid for that item is removed from textbox. This is because listbox2 is not databound and valueid is generated from listbox1.

        L 1 Reply Last reply
        0
        • S scottichrosaviakosmos

          ok, but what about valueid which is populated when i add items in lstbox2 from listbox1. i have a button "ADD". when i select item in listbox1 and click add button item is added to listbox2 and so as its valueid in textbox. but when i click on remove button the item will get removed from listbox2 but valuid for that item is removed from textbox. This is because listbox2 is not databound and valueid is generated from listbox1.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          scottichrosaviakosmos wrote:

          and valueid is generated from listbox1.

          At what time? Easiest solution would be to call that generate-routine again, otherwise you'd have to manually cut it from the string, before deleting the item.

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          S 1 Reply Last reply
          0
          • L Lost User

            scottichrosaviakosmos wrote:

            and valueid is generated from listbox1.

            At what time? Easiest solution would be to call that generate-routine again, otherwise you'd have to manually cut it from the string, before deleting the item.

            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

            S Offline
            S Offline
            scottichrosaviakosmos
            wrote on last edited by
            #5

            Ok, let me explain in details. I have a form which has 2 listboxs, textbox and 2 buttons. lst1 and lst2. Also has 2 buttons "add" and "Remove". lst1 is populated from a database table which has 2 fields : "Name" ad "emailid". lst1 will show items "name" from table column "name". eg: ronny, danial... when i select an item(name) in lst1 and click Add button then the name will be added in lst2(lst2 is not connected to datasource). Also the displayvalue member or emailid with respect to the name selected in lst1 will be added to the textbox.(this is working fine). Now, when i select an item in lst2 which was added from lst1 and then click on Remove button then the item(name) should be removed from lst2(this is also working fine) and also the emailid corresponding to the value(name) selected in lst2 should be removed from textbox. emailid on selectitem of lst2 is not getting removes since the lst2 is connected to database. lst is adding its item from lst1. I hope now the scenario is clear.!:| Cheers

            L 1 Reply Last reply
            0
            • S scottichrosaviakosmos

              Ok, let me explain in details. I have a form which has 2 listboxs, textbox and 2 buttons. lst1 and lst2. Also has 2 buttons "add" and "Remove". lst1 is populated from a database table which has 2 fields : "Name" ad "emailid". lst1 will show items "name" from table column "name". eg: ronny, danial... when i select an item(name) in lst1 and click Add button then the name will be added in lst2(lst2 is not connected to datasource). Also the displayvalue member or emailid with respect to the name selected in lst1 will be added to the textbox.(this is working fine). Now, when i select an item in lst2 which was added from lst1 and then click on Remove button then the item(name) should be removed from lst2(this is also working fine) and also the emailid corresponding to the value(name) selected in lst2 should be removed from textbox. emailid on selectitem of lst2 is not getting removes since the lst2 is connected to database. lst is adding its item from lst1. I hope now the scenario is clear.!:| Cheers

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              scottichrosaviakosmos wrote:

              Now, when i select an item in lst2 which was added from lst1 and then click on Remove button then the item(name) should be removed from lst2(this is also working fine) and also the emailid corresponding to the value(name) selected in lst2 should be removed from textbox.

              So, everything is working fine, except for the removal of the email-address in the textbox?

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              S 1 Reply Last reply
              0
              • L Lost User

                scottichrosaviakosmos wrote:

                Now, when i select an item in lst2 which was added from lst1 and then click on Remove button then the item(name) should be removed from lst2(this is also working fine) and also the emailid corresponding to the value(name) selected in lst2 should be removed from textbox.

                So, everything is working fine, except for the removal of the email-address in the textbox?

                Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                S Offline
                S Offline
                scottichrosaviakosmos
                wrote on last edited by
                #7

                yes.

                L 1 Reply Last reply
                0
                • S scottichrosaviakosmos

                  yes.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  ..and the email-address needs to be removed from the textbox, if the "remove" button is clicked? Emailaddresses are unique, so you could try and replace that part of the textbox with an empty string, like so;

                  textBox1.Text = textBox1.Text.Replace("et@home.nl", "");

                  Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                  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