Sharpeye500
Sharpeye500

Reputation: 9063

Not able to open a form in design mode

When i open form, i can't get into design mode and i get this error:

The variable 'MonthViewCalendar'
    (internal 
        Infragistics.Win.UltraWinSchedule.UltraMonthViewSingle 
        MonthViewCalendar;)
is either undeclared or was never assigned. 

Any idea why a form doesn't go into design mode? I am using VS 2010.

I tried - Clean solution, restarting VS and reopening, but that didn't solve my issue.

Upvotes: 2

Views: 9192

Answers (5)

rampagingrabbits
rampagingrabbits

Reputation: 21

I know my answer does not fit the OPs question exactly but I thought I would add it because it appears to be loosely related...

My form also suddenly was not able to be opened in designer mode inside Visual Studio 19 and I did not know why.

I applied the fix above by @david-forge and ONLY then did Visual Studio show the actual issue which was...

The class client_Form can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again.

It's a strange situation where Visual Studio will NOT show this error message unless you add the Form fix (for myself at least).

So it seems to be some special rule that the forms class MUST BE THE FIRST class in the form's source file, otherwise you will lose the ability to open the form in the designer, and Visual Studio will NEVER show you the reason why doh

In theory Visual Studio should be checking this and reporting it as it finds it, not just not reporting it, and removing the design capabilities without any explanation.

Here is a small example code which will cause the form in question to NOT be able to be edited in designer mode...

using System;
using System.Drawing;
using System.Text;

namespace MyProject
{
    public class this_breaks_designer_capabilities
    {

    }

    public partial class client_Form : Form
    {

        public client_Form()
        {
            InitializeComponent();
        }
    }
}

Simply moving the this_breaks_designer_capabilities class to be below the client_Form class will restore the forms ability to be edited in designer mode.

NOTE: I do not know if this feature exists in higher versions of Visual Studio. Can anyone confirm?

Upvotes: 0

voltento
voltento

Reputation: 877

It can happen if you insert a new class above an implementation of the class.

Upvotes: 3

David Ford
David Ford

Reputation: 785

Sometimes you may find that the project file loses the correct subtype that the file needs to open in design mode.

To fix:

  • Shutdown VS, then edit the projects ".csproj" file using a text editor
  • Look for the <Compile Include="MyFile.cs">
  • If there's no "<SubType>Form</SubType>" then add it back in as follows

    <Compile Include="MyForm.cs"> <SubType>Form</SubType> </Compile>

Upvotes: 11

user16324
user16324

Reputation:

What works for me is to close and relaunch Visual Studio, then rebuild. After that the form can be opened in design mode. I wouldn't say I particularly like my solution, but I haven't come up with a more sure-fire solution.

Edit: I've only ever encountered this problem when there's an Infragistics control on the form.

Upvotes: 1

coltech
coltech

Reputation: 389

Go into your Form.Designer.cs file and remove the declaration for "abcd". Then reload it in your designer.

Upvotes: 3

Related Questions