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

N

nphc67

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?
 
I

Ian Klyss

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top