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. Updating Listbox Items

Updating Listbox Items

Scheduled Pinned Locked Moved C#
helpquestionannouncement
5 Posts 4 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
    monrobot13
    wrote on last edited by
    #1

    Hi Yallz, I have a list box that you can edit the items in (click a button, and it pops up a form so you enter the info you want), the problem I'm encoutering is that once the user presses OK on the edit form the listbox isn't update with the new informatin. Is there anyway to update a listbox item without removing it and then adding it back? Thanks! - monrobot13

    A L 2 Replies Last reply
    0
    • M monrobot13

      Hi Yallz, I have a list box that you can edit the items in (click a button, and it pops up a form so you enter the info you want), the problem I'm encoutering is that once the user presses OK on the edit form the listbox isn't update with the new informatin. Is there anyway to update a listbox item without removing it and then adding it back? Thanks! - monrobot13

      A Offline
      A Offline
      albean
      wrote on last edited by
      #2

      Are you doing something like this in your click event: MyForm f = new MyForm(); f.Show(); If you are then your problem is you are getting a NEW form each time with an empty list. Try hiding the listbox form when you are done with it. In the button click event unhide it.

      M 1 Reply Last reply
      0
      • A albean

        Are you doing something like this in your click event: MyForm f = new MyForm(); f.Show(); If you are then your problem is you are getting a NEW form each time with an empty list. Try hiding the listbox form when you are done with it. In the button click event unhide it.

        M Offline
        M Offline
        monrobot13
        wrote on last edited by
        #3

        That's not it. I actually serialize all the listbox items when the form is closed and then deserialize them when it's loaded. When I do this it does show the new information. When you add an item to a listbox it call's it ToString function to get the text to display. I want to update the text that is being displayed without removing and readding the item. - monrobot13

        S 1 Reply Last reply
        0
        • M monrobot13

          That's not it. I actually serialize all the listbox items when the form is closed and then deserialize them when it's loaded. When I do this it does show the new information. When you add an item to a listbox it call's it ToString function to get the text to display. I want to update the text that is being displayed without removing and readding the item. - monrobot13

          S Offline
          S Offline
          StealthyMark
          wrote on last edited by
          #4

          Don't use ToString(). Add the item itself, or better yet use databinding to display a complete collection. When you edit the collection entry, the listbox is updated (possibly after a call to Refresh()).

          1 Reply Last reply
          0
          • M monrobot13

            Hi Yallz, I have a list box that you can edit the items in (click a button, and it pops up a form so you enter the info you want), the problem I'm encoutering is that once the user presses OK on the edit form the listbox isn't update with the new informatin. Is there anyway to update a listbox item without removing it and then adding it back? Thanks! - monrobot13

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

            hi, i encountered a similar problem some time back. I do not have the code with me right now, but i hope that i can put the solution down in words. 1: create a custom 'event' class that gets/sets a string. This is the string that the user will be updating when he uses the new form (by using 'set' property). 2: try to 'fire' events when the user is done with the edit box. (I am assuming that both the edit window and the main window are on same thread, else you will have to call an invoke on the form). 3: send the string as an argument to the main Form. 4: define an event handler on the main form that will handle your custom events. This will retrieve the string using the 'get' property. i'll try and post the code if i can. hope this helps. regards, Mithun.

            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