weird problem with ComboBox - DataSource contains data, but the Items collection stays empty
-
I created a custom control which simply is a data-bound
ComboBox
. It has a custom property that causes anArrayList
ofKeyValuePair
elements to be passed to theDataSource
property. It also sets theDisplayMember
andValueMember
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 onForm1
everything is fine, while onForm2
theItems
collection stays empty, although theDataSource
property contains data and it is exactly the same data (pulled from the database in the same way) that I use in case ofForm1
. I tried to use aDataTable
instead of anArrayList
, but it changed nothing. Does anybody have any suggestions? -
I created a custom control which simply is a data-bound
ComboBox
. It has a custom property that causes anArrayList
ofKeyValuePair
elements to be passed to theDataSource
property. It also sets theDisplayMember
andValueMember
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 onForm1
everything is fine, while onForm2
theItems
collection stays empty, although theDataSource
property contains data and it is exactly the same data (pulled from the database in the same way) that I use in case ofForm1
. I tried to use aDataTable
instead of anArrayList
, but it changed nothing. Does anybody have any suggestions?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 theItems
collection in the window's constructor. Even though I put my code after theInitializeComponent
method, the combo box must've been still not fully initialized. I moved the code toForm.Load
event and everything works fine.