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. How to update ComboBox/ListBox bound to ArrayList?

How to update ComboBox/ListBox bound to ArrayList?

Scheduled Pinned Locked Moved C#
comhelptutorialquestionannouncement
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.
  • T Offline
    T Offline
    therealmccoy
    wrote on last edited by
    #1

    I have a ComboBox that has the DataSource property set to an ArrayList. I am using the following code to force the ComboBox to update when I make changes to the ArrayList: this.cboTrains.DataSource = null; this.cboTrains.DataSource = alTrains; this.cboTrains.DisplayMember = "Name"; Is there a better way? Also have the same issue with ListBox. Thanks. www.lovethosetrains.com

    T 1 Reply Last reply
    0
    • T therealmccoy

      I have a ComboBox that has the DataSource property set to an ArrayList. I am using the following code to force the ComboBox to update when I make changes to the ArrayList: this.cboTrains.DataSource = null; this.cboTrains.DataSource = alTrains; this.cboTrains.DisplayMember = "Name"; Is there a better way? Also have the same issue with ListBox. Thanks. www.lovethosetrains.com

      T Offline
      T Offline
      Travis D Mathison
      wrote on last edited by
      #2

      Try calling the "Refresh" method on the comboBox to make it update instead of resetting its data source...

      T 1 Reply Last reply
      0
      • T Travis D Mathison

        Try calling the "Refresh" method on the comboBox to make it update instead of resetting its data source...

        T Offline
        T Offline
        therealmccoy
        wrote on last edited by
        #3

        Nope.. Doesn't do the trick. The Refresh method just forces the control to redraw (not update what it knows).. I was thinking of adding an event that fires when the ArrayList is changed and entending the control (ListBox/ComboBox) to have a new method that updates the bindings. I'm just not wanting to overly complicate it (or do more work then needed). Thanks. www.lovethosetrains.com

        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