I have a dropdown list that I want to show only certain options when a bool is true of false.
if (mainForm.boolEdit == true)
{
this.cmbStatusBox.Items.AddRange(new object[] {
"Cooking",
"In-transit",
"Delivered"});
}
else
{
this.cmbStatusBox.Items.AddRange(new object[] {
"Ordered"});
}
I put this code into the saveForm.Designer.cs and got the following error:
The designer cannot process the code at line 205:
if (mainForm.boolEdit == true)
{
this.cmbStatusBox.Items.AddRange(new object[] {
“Cooking”,
“In-transit”,
“Delivered”});
}
else
{
this.cmbStatusBox.Items.AddRange(new object[] {
“Ordered”});
}
The code within the method ‘InitializeComponent’ is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.
What are my alternatives?
EDIT! I have now put the designer back to normal as follows :
this.cmbStatusBox.Items.AddRange(new object[] {
"Ordered",
"Cooking",
"In-transit",
"Delivered"});
and in the formload, i have put the following:
if (mainForm.boolEdit == true)
{
this.cmbStatusBox.Items.AddRange(new object[] {
"Cooking",
"In-transit",
"Delivered"});
}
else
{
this.cmbStatusBox.Items.AddRange(new object[] {
"Ordered"});
}
Problem is, I now have both the designer and the formload putting names into the dropdown. Ideally i just want the ones from the second lot of code, but when i click edit (which brings up what has already been done), the dropdowns are populated by what is saved if the designer populates it. If the formload populates the dropdown, when i edit, the dropdown doesnt specify what has already been saved.
Any ideas?
You should not modify the
.designer.csfile manually. An alternative would be to use the constructor of the form to do this initialization or in some load event.