hsueh001 Posted February 19, 2009 Posted February 19, 2009 (edited) This is for a WinForms environment. I am trying to create a ComboBox, that contains all the Countries in my database where I don't have to "hook" it up on every single form that it will be used. So I tried to do some inheritance, I inherited it from a ComboBox. In the constructor I simply connect to the Sql database and query a list of Id and country values. However when I drag this ComboBox into my WinForm I'm getting some code generation in the Designer.cs under the InitializeComponent(). The problem is the autocode generator generates two lines. this.comboBoxCountry.DataSource = ((object)(resources.GetObject("comboBoxCountry.DataSource"))); AND this.comboBoxCountry.Items.AddRange(new object[] { ((object)(resources.GetObject("comboBoxCountry.Items")))}); The order they are generated cause the second line to error. If I move the second line above the first, the error disappears. The error that I'm getting is: "Items collection cannot be modified when the DataSource property is set." Is there any way around this? Edited February 20, 2009 by hsueh001 Quote
Administrators PlausiblyDamp Posted February 28, 2009 Administrators Posted February 28, 2009 Any chance you could post your existing code? It maight help to make things a bit clearer. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
feurich Posted March 2, 2009 Posted March 2, 2009 Maybe i am misunderstanding you but this could be a solution. You could programmatically fill a dataset with the country values and id's and afterwards you can bind this dataset to the combobox. In this way you can first set the datasource property of the combobox and bind the dataset afterwards. Hope it helps!! Quote Trust the Universe
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.