ComboBox - selected item not set

B

Backwater Geezer

More or less the code looks like this

ArrayList _contacts; // during test it has 9 objects (ClientContact)

cbxContact.DisplayMember = "Name;
cbxContact.ValueMember = "Name;

cbxContact.DataSource = _contacts;
cbxContact.SelectedItem = null;
cbxContact.SelectedIndex = -1;

public void ShowContact(int ContactId)
{
ClientContact CLCO = null;

// always use current DataSource
ArrayList data = (ArrayList)cbxContact.DataSource;

foreach (ClientContact clco in data)
{
if (clco.Id == ContactId)
{
CLCO = clco;
break;
}
}

cbxContact.SelectedItem = CLCO; // sometimes it works, sometimes not,
// drop down list has correct

if (cbxContact.SelectedItem == null)
{
cbxContact.SelectedIndex = data.IndexOf(CLCO);
// at this stage SelectedItem is no longer null and shows correct data
if (cbxContact.SelectedItem != CLCO)
MessageBox.Show("WHAT THE **** GOING ON!!!");
}

}

cbxContact has no events attached to it.

Any thoughs on this?

MH
 

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