ComboBox Items binding issue

R

Rod

I am trying to select a particular ComboBox item programmatically
immediately after setting the the DataSource of the ComboBox to an
ArrayList. But there are no Items in the ComboBox after setting the
DataSource so I am unable to select a particular item. What am I
missing?

Thanks,
Rod Early ([email protected])

My code is something like this:

public class ItemClass
{
private string _ID;
private string _Text;

public string ID...
public string Text...

public ItemClass(string ID, string Text)...
}

....

drop = new ComboBox();
drop.DisplayMember = "Text";
drop.ValueMember = "ID";

ArrayList aList = new ArrayList();
PopulateArrayList(aList);

drop.DataSource = aList;

// Would like to search for item to select here, but drop.Items.Count =
0 !!!
 
A

Arun

Check to see if PopulateArrayList fills the data.
Post PopulateArrayList code, if the problem still exists,
Cheers,
Arun.
 
R

Rod

Arun, thanks for responding. I am certain that PopulateArrayList fills
the data, as I have confirmed that via the debugger.

Thanks,
Rod
 
R

Ruslan Trifonov

assign the parent property of the combobox:
Assuming you populate the combobox in the form where you will display it you
should have a line like this:


drop.Parent=this;


Place this line before checking items property.
 
A

azerty

To work fine, you MUST develop your own ArrayList Class with

public ItemClass this[int index]
{
get
{
return (ItemClass)base[index];

}
set
{
base[index] = value;
}
}
 

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