.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.
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."
Well are you sure the source is filled with string objects?
精彩评论