PC Review


Reply
Thread Tools Rate Thread

ComboBox - selected item not set

 
 
Backwater Geezer
Guest
Posts: n/a
 
      29th Jan 2009
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

 
Reply With Quote
 
 
 
 
Martin M
Guest
Posts: n/a
 
      4th Feb 2009
Would you like to try the DaisyCombo from http://www.springsys.com



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



 
Reply With Quote
 
Backwater Geezer
Guest
Posts: n/a
 
      9th Feb 2009
Martin M wrote:

> Would you like to try the DaisyCombo from http://www.springsys.com


Do you think I'm so stupid to buy something like that?

MH
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get selected item of ComboBox Aejaz Rathore Microsoft C# .NET 1 22nd Dec 2009 04:52 PM
Combobox not display selected item Mark Boettcher Microsoft C# .NET 3 21st Dec 2007 07:43 PM
Combobox selected item is not highlighted. Academia Microsoft VB .NET 2 16th Oct 2007 03:29 PM
combobox item selected =?Utf-8?B?UExE?= Microsoft Access Forms 0 1st Mar 2007 12:51 PM
ComboBox selected item ballabali Microsoft Excel Discussion 1 15th Dec 2005 03:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:49 AM.