Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: enums suck! Pin
Alvaro Mendez15-Oct-03 11:10
Alvaro Mendez15-Oct-03 11:10 
GeneralRe: enums suck! Pin
Heath Stewart15-Oct-03 11:52
protectorHeath Stewart15-Oct-03 11:52 
GeneralRe: enums suck! Pin
Alvaro Mendez15-Oct-03 13:04
Alvaro Mendez15-Oct-03 13:04 
GeneralRe: enums suck! Pin
bjoernen16-Oct-03 3:36
bjoernen16-Oct-03 3:36 
GeneralRe: enums suck! Pin
Richard Lowe16-Oct-03 3:37
Richard Lowe16-Oct-03 3:37 
GeneralToolbar Pin
Gary Kirkham15-Oct-03 8:50
Gary Kirkham15-Oct-03 8:50 
GeneralRe: Toolbar Pin
Heath Stewart15-Oct-03 11:54
protectorHeath Stewart15-Oct-03 11:54 
GeneralCustom Controls and Enum value Types Pin
Douglas Troy15-Oct-03 5:45
Douglas Troy15-Oct-03 5:45 
The Scenario

I've created a custom control that has a public property that is of an enumerated value type. I have created an accessor method to get/set that property and have it 'binded'. Finally, in the constructor for the control, I set that property to a default value, referencing the full namespace of the enum value type to ensure no conflicts with other controls would exist (see sample code below):
<br />
namespace MyControls {<br />
<br />
  public class MyCustomControl : System.Windows.Forms.Label <br />
  {<br />
    public enum MyLabelType { High, Low, Special, Hidden };<br />
<br />
    private MyLabelType myLabelType;<br />
<br />
    // constructor<br />
    public MyCustomControl <br />
    {<br />
       // set default value<br />
       myLabelType = MyControls.MyCustomControl.MyLabelType.Special;<br />
    }<br />
<br />
  ...<br />
<br />
    // public accessor<br />
    [Bindable(true), Category("Custom Properties"),<br />
     Description("My Custom Control ...")]<br />
    public MyControls.MyCustomControl.MyLabelType LabelType<br />
    {<br />
      get ... <br />
      set ...<br />
    } <br />
<br />
...<br />
<br />
  }<br />
}<br />

The Problem

I drop the custom control onto a form and set my properties without a hitch. I add a using clause to my code for that namespace and do a build. I get no errors, I can run the application without issues ... Etc. However, if I close the solution/project, and open it back up, then open that form back up in design mode, I get errors on that enumerated property that indicates "The variable 'MyLabelType' is either undeclared or was never assigned".

When I attempt to set a variable to this value type my code, the intellisense doesn't "find" the enum value type. (Example):

MyControls.MyCustomControl.MyLabelType is not found ...

Yet if I open custom control solution in studio, rebuild it, and then go BACK to my solution that uses the custom control, studio can now "see" the enumerated data type ...

I have tried to set the "DefaultValue" on the property accessor for this type, but to no avail. It does not seem to affect the outcome.

Any suggestions or answers as to what I am doing wrong, or to why this is happening? I'm guessing the solution is something simple that I am just overlooking. Sigh | :sigh:

TIA


D.
GeneralPassing a Form reference to a new Form Pin
mikemilano15-Oct-03 4:50
mikemilano15-Oct-03 4:50 
GeneralRe: Passing a Form reference to a new Form Pin
Mike Dimmick15-Oct-03 4:59
Mike Dimmick15-Oct-03 4:59 
GeneralBindingContext Pin
Anonymous15-Oct-03 4:45
Anonymous15-Oct-03 4:45 
GeneralWindows Form TabPage Pin
Jubal15-Oct-03 4:19
Jubal15-Oct-03 4:19 
GeneralRe: Windows Form TabPage Pin
Wjousts15-Oct-03 5:49
Wjousts15-Oct-03 5:49 
GeneralUsing C# in MFC Project Pin
Anonymous14-Oct-03 23:53
Anonymous14-Oct-03 23:53 
GeneralVersioning Solution Pin
Member 37818914-Oct-03 20:55
Member 37818914-Oct-03 20:55 
GeneralRe: Versioning Solution Pin
Douglas Troy15-Oct-03 6:26
Douglas Troy15-Oct-03 6:26 
GeneralRe: Versioning Solution Pin
Heath Stewart15-Oct-03 11:59
protectorHeath Stewart15-Oct-03 11:59 
GeneralRe: Versioning Solution Pin
Douglas Troy16-Oct-03 4:44
Douglas Troy16-Oct-03 4:44 
GeneralRe: Versioning Solution Pin
15-Oct-03 19:38
suss15-Oct-03 19:38 
GeneralRe: Versioning Solution Pin
Member 37818915-Oct-03 23:20
Member 37818915-Oct-03 23:20 
GeneralRe: Versioning Solution Pin
Douglas Troy16-Oct-03 4:58
Douglas Troy16-Oct-03 4:58 
GeneralVBScript to C# Pin
CyberKewl14-Oct-03 20:29
CyberKewl14-Oct-03 20:29 
GeneralRe: VBScript to C# Pin
Mike Dimmick14-Oct-03 23:53
Mike Dimmick14-Oct-03 23:53 
GeneralRe: VBScript to C# Pin
CyberKewl15-Oct-03 0:51
CyberKewl15-Oct-03 0:51 
GeneralRe: VBScript to C# Pin
Mike Dimmick15-Oct-03 1:30
Mike Dimmick15-Oct-03 1:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.