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. weird problem with ComboBox - DataSource contains data, but the Items collection stays empty

weird problem with ComboBox - DataSource contains data, but the Items collection stays empty

Scheduled Pinned Locked Moved C#
databasehelpquestion
2 Posts 1 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
    Marek Grzenkowicz
    wrote on last edited by
    #1

    I created a custom control which simply is a data-bound ComboBox. It has a custom property that causes an ArrayList of KeyValuePair elements to be passed to the DataSource property. It also sets the DisplayMember and ValueMember properties. What's weird, is the fact that my control sometimes works fine and sometimes it doesn't. I have no idea why, but when I put on Form1 everything is fine, while on Form2 the Items collection stays empty, although the DataSource property contains data and it is exactly the same data (pulled from the database in the same way) that I use in case of Form1. I tried to use a DataTable instead of an ArrayList, but it changed nothing. Does anybody have any suggestions?

    M 1 Reply Last reply
    0
    • M Marek Grzenkowicz

      I created a custom control which simply is a data-bound ComboBox. It has a custom property that causes an ArrayList of KeyValuePair elements to be passed to the DataSource property. It also sets the DisplayMember and ValueMember properties. What's weird, is the fact that my control sometimes works fine and sometimes it doesn't. I have no idea why, but when I put on Form1 everything is fine, while on Form2 the Items collection stays empty, although the DataSource property contains data and it is exactly the same data (pulled from the database in the same way) that I use in case of Form1. I tried to use a DataTable instead of an ArrayList, but it changed nothing. Does anybody have any suggestions?

      M Offline
      M Offline
      Marek Grzenkowicz
      wrote on last edited by
      #2

      I found a solution. It seems that the problem was caused by the fact that in one the windows (Form2) I was trying to access the Items collection in the window's constructor. Even though I put my code after the InitializeComponent method, the combo box must've been still not fully initialized. I moved the code to Form.Load event and everything works fine.

      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