|
-
Mar 22nd, 2004, 12:19 PM
#1
Thread Starter
Frenzied Member
adding "months" to a combobox [RESOLVED]
I've been trying to do a loop to add the names of each month in a combo box. I haven't been successful. The best I've been able to do is get the numeric representation of this month 12 times 
I figured there would've been an enumerator ofr the months but apparently not.
Any ideas how to loop through the months and display them. preferably starting with THIS month and ending with LAST month.
eg.
March
.
.
.
.
.
February
so NEXT month, it looks like this:
April
.
.
.
March
as always, thanks.
Last edited by Andy; Mar 23rd, 2004 at 03:00 PM.
-
Mar 22nd, 2004, 12:36 PM
#2
Sleep mode
One way .
VB Code:
Dim months As New DateTimeFormatInfo
For i As Integer = 1 To 12
MsgBox(months.GetMonthName(i))
Next
-
Mar 22nd, 2004, 12:37 PM
#3
Sleep mode
Two ways now :
VB Code:
For Each s As String In months.MonthNames
MsgBox(s)
Next
-
Mar 22nd, 2004, 12:44 PM
#4
Thread Starter
Frenzied Member
aha! I missed the DateTimeFormatInfo().
that makes all the difference in the world!!
thanks pirate 
added:
you must import this namespace to the project:
System.Globalization
Last edited by Andy; Mar 22nd, 2004 at 12:50 PM.
-
Mar 22nd, 2004, 12:50 PM
#5
Wouldn't it be better if you preselect the current month? This way almost seems like you're wrapping into the new year...
Taking into account the current culture:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
// Get the current month.
int month = DateTime.Now.Month;
// Get a string array of the current culture's month names.
System.Globalization.DateTimeFormatInfo formatInfo =
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;
string[] monthNames = formatInfo.MonthNames;
// Populate the combo.
for (int i = month; i < monthNames.Length; i++)
if (monthNames[i] != String.Empty)
DropDownList1.Items.Add(monthNames[i]);
for (int i = 0; i < month; i++)
if (monthNames[i] != String.Empty)
DropDownList1.Items.Add(monthNames[i]);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|