enum 'expansion' / 'extention'

  • Thread starter Thread starter Andrew Robinson
  • Start date Start date
A

Andrew Robinson

Not sure what to call this, but I have a series of User Controls that
display the days of the week. Usually using a set of radio buttons. Works
very well.

I display the user controls in a form and typically allow the user to select
only a single day within a single week. There are at times, up to 8 weeks
displayed, but the user is allowed only one day to be selected across all
controls. As the use clicks on a radio button, all other buttons on all
other user controls are cleared. I am doing this by fireing an event from
the control to the windows form. Again, works very well.

I use the 'System.DayOfWeek' enumeration to get and set the value of the
control. I even use this enumeration in the even on the control that is
fired when the user changed the selection. Again works very well.

Now, I would like to add a state that has no selection on the control. I am
currently doing this with an additional Boolean flag, but is there any way
that I can in effect add another value to System.DayOfWeek. This would be
really helpful as I could continue to pass this value around my application
without worrying about conversion.

Or, is this a possible use for nullable types in 2.0?

-Andrew
 
Hi Andrew,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add a new null value to the
System.DayOfWeek enumeration. If there is any misunderstanding, please feel
free to let me know.

Currently, we cannot add an enum to the DayOfWeek enumeration. So I think
the best workaround is to add a flag which indicates if the object has
value.

However, in .NET framework 2.0, we'll have nullable types for value types.
You can just declare an object as follows:

Nullable<System.DayOfWeek> a = null;
or
Nullable<System.DayOfWeek> a = DayOfWeek.Sunday;

We can use a.HasValue to check if it is a null value.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
You're welcome, Andrew.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top