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?
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?
Last edited: