473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return month from dropdown as integer

Hi,

I am new to C# so forgive my ignorance.

I need to write a month 'number' to a DB, ie January = 1, March=3 etc etc...

I have the month description in a combo box. I used an enum " enum
month{January = 1,February, March....... etc } " to load the combo.

I wanted to use the same to resolve the String retrieved form the combo into
the actual enum value.

How would I do this ??

I attempted to do an 'Array.binarysearch' having populated an array with the
months of the year. That didnt work either.

Any help appreciated.

Jon.
Apr 26 '06 #1
2 6530
Bishman,

It depends how you populate the combobox.
Example
enum month{January = 1,February, March....... etc }

you can populate the combobox
combobox.Items.Add(month.January);
combobox.Items.Add(month.February);
etc.

you can do: (int)combobox.SelectedItem;

If you populate the combobox with the names of the enumeration items you can
go for

(int)Enum.Parse(typeof(Months), str)
--
HTH
Stoitcho Goutsev (100)

"Bishman" <jo*************@btinternet.com> wrote in message
news:OE**************@TK2MSFTNGP03.phx.gbl...
Hi,

I am new to C# so forgive my ignorance.

I need to write a month 'number' to a DB, ie January = 1, March=3 etc
etc...

I have the month description in a combo box. I used an enum " enum
month{January = 1,February, March....... etc } " to load the combo.

I wanted to use the same to resolve the String retrieved form the combo
into the actual enum value.

How would I do this ??

I attempted to do an 'Array.binarysearch' having populated an array with
the months of the year. That didnt work either.

Any help appreciated.

Jon.

Apr 26 '06 #2
Hi Stoitcho,

Many thanks, the line " (int)Enum.Parse(typeof(Months), str) " is the
one I wanted, works fine.

I had a play around with Enum.Parse today also but just couldnt get it to
play ball.

Many thanks, Much appreciated.

Bish.
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:uz**************@TK2MSFTNGP02.phx.gbl...
Bishman,

It depends how you populate the combobox.
Example
enum month{January = 1,February, March....... etc }

you can populate the combobox
combobox.Items.Add(month.January);
combobox.Items.Add(month.February);
etc.

you can do: (int)combobox.SelectedItem;

If you populate the combobox with the names of the enumeration items you
can go for

(int)Enum.Parse(typeof(Months), str)
--
HTH
Stoitcho Goutsev (100)

"Bishman" <jo*************@btinternet.com> wrote in message
news:OE**************@TK2MSFTNGP03.phx.gbl...
Hi,

I am new to C# so forgive my ignorance.

I need to write a month 'number' to a DB, ie January = 1, March=3 etc
etc...

I have the month description in a combo box. I used an enum " enum
month{January = 1,February, March....... etc } " to load the combo.

I wanted to use the same to resolve the String retrieved form the combo
into the actual enum value.

How would I do this ??

I attempted to do an 'Array.binarysearch' having populated an array with
the months of the year. That didnt work either.

Any help appreciated.

Jon.


Apr 26 '06 #3

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

Similar topics

6
2973
by: Hasanain F. Esmail | last post by:
Hi all, I sincerly thank you all in advance for your help to solve this problem. I have been trying to find a solution to this problem for sometime now but have failed. I am working on a...
6
2944
by: James Fortune | last post by:
Several U.S. holidays are defined as the Nth Xday of a given month. For example, Thanksgiving Day is on the 4th Thursday in November. I found the following functions useful in calculating the date...
13
2137
by: Sara | last post by:
I have a query that pulls data for the month, using the Month End Date from a form (user enters) as criteria. It works. I want to use the same query to pull "month to date" data, on a weekly...
8
9948
by: felecha | last post by:
Is there a control that I can put on a Form that would let a user select just the month value? I tried to find a way to make the DateTimePicker or the Month Calendar do what I want but I can't. ...
34
9253
by: prosoft | last post by:
When I use Dim myDTFI As DateTimeFormatInfo = New CultureInfo("he-IL", True).DateTimeFormat Dim strhmon1 As String = (myDTFI.GetMonthName(hmon1)) MsgBox(strhmon1) I get the local name of the...
6
3257
by: Zeba | last post by:
Hi, I have a page with a calendar and two datalist items - one containing month values and the other, year values. Depending on the month/year value chosen ( in text/string format ) I should be...
10
4352
by: YvesDM | last post by:
Hi, How can I do this, I've got a little form with a dropdown. <select name="maand"> <option value='1'>januari</option> <option value='2'>februari</option> <option value='3'>maart</option>...
3
5716
by: gmazza via AccessMonster.com | last post by:
Hi there, I am trying to run a report using a parameter for where the user chooses a month from a combo box. Then on the report, I want it to compare the month to a date field and choose only...
3
3000
by: One | last post by:
Hi group - I want to do a SELECT based on a date range - but mySQL syntax expects the month range to be two digits. So I have converted the month to show the leading zero like this : ...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
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
5614
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,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
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
1532
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 ...
0
409
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.