sarsnake
sarsnake

Reputation: 27723

.net ComboBox.Items.Add("testvalue") throws exception

I am using Compact Framework and the statement below throws exception:

 ComboBox cmbList  = new ComboBox();

    //source set here
   List<string> items = new List<string>();
   items.AddRange(GetNumbers());     
   cmbList.DataSource = ovenNumbers;


    // where GetNumbers() return List<string> object        
    //then down the road I need to dynamically add one more item to the list of items

     cmbList.Items.Add("TESTVALUE");

MSDN only lists one exception - for null parameter, which is clearly not the case. What am I doing wrong? Thanks!

EDITED: I can't view the error message since I don't have the module required to view errors installed on my thin client.

Upvotes: 1

Views: 861

Answers (2)

sarsnake
sarsnake

Reputation: 27723

Found the answer apprently once DataSource property is set,it can't be changed http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.datasource%28v=vs.90%29.aspx

"When the DataSource property is set, a user cannot modify the items collection."

Upvotes: 2

Pablo Rodda Donate
Pablo Rodda Donate

Reputation: 290

Well are you sure the source is filled with string objects?

Upvotes: 0

Related Questions