473,491 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Create Flaggable Enum From Checkbox List

I have an enum for the days of the week: DaysOfTheWeek.Sunday,
DaysOfTheWeek.Monday, etc. that is flaggable so that mutliple days of
the week can be indicated.

I also have a checkbox list representing the days of the week. How
can I "convert" the checked items into a DaysOfTheWeek enum that
represents which days are selected in the checked list box?

Thanks!
Bryan Green
Jul 3 '08 #1
2 6216
You should be able to cast each item in turn to a DaysOfTheWeek, and
"or" them together; example below.

Marc

using System;
using System.Windows.Forms;
[Flags]
enum DOW
{
None = 0, Mon = 1, Tue = 2, Wed = 4, Thur = 8, Fri = 16, Sat = 32,
Sun = 64
}
static class Program
{
static void Main()
{
Application.EnableVisualStyles();

CheckedListBox clb = new CheckedListBox { Dock =
DockStyle.Fill };
foreach(DOW dow in Enum.GetValues(typeof(DOW))) {
clb.Items.Add(dow,false);
}
Button btn = new Button { Dock = DockStyle.Bottom, Text =
"Show Me"};
btn.Click += delegate
{
DOW tally = DOW.None;
foreach (DOW dow in clb.CheckedItems)
{
tally |= dow;
}
MessageBox.Show(btn, tally.ToString(), "Checked days");
};
Application.Run(new Form { Controls = { clb, btn } });
}
}
Jul 3 '08 #2
Worked like a champ! Thank you VERY much.

Bryan

Jul 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8819
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
5
4510
by: Sriram Rajagopalan | last post by:
Hi, Is the extra comma at the end of an enumerator-list valid according to the C standards? With the gcc compiler the following is valid: enum DAYS {MONDAY, TUESDAY, }day1; gcc does not...
2
30119
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
21
4568
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
2
3384
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
10
23545
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize...
34
11126
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
5
5102
by: Bill Gower | last post by:
I have a group of 7 checkboxes representing the days of the week. I have an enum that that corresponds to the days ex. DaysOfWeek.Sunday, DaysOfWeek.Monday etc. I have a library that has a...
4
2413
by: colonial | last post by:
I was wondering if what I'm trying to do in Access XP and 2003 is possible. I've looked at countless templates and samples and havn't seen anything like what I want to do to be able to construct it....
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.