-
Jun 30th, 2007, 05:15 PM
#1
Thread Starter
Member
DateTimePicker, display MMM-yy only
I want my DateTimePicker to display the Month and year only.
So I have set the CustomFormat to MMM-yy.
But in runtime when I change the month I get the following error
"Year, Month, and Day parameters describe an un-representable DateTime."
Is it possible to have the month and year only or do I need to include the day also??
-
Jun 30th, 2007, 05:26 PM
#2
Re: DateTimePicker, display MMM-yy only
How do you change the month in code?
-
Jun 30th, 2007, 05:57 PM
#3
Re: DateTimePicker, display MMM-yy only
You don't need to include the day:
vb.net Code:
Me.DateTimePicker1.Format = DateTimePickerFormat.Custom
Me.DateTimePicker1.CustomFormat = "MMM-yy"
-
Jun 30th, 2007, 06:12 PM
#4
Thread Starter
Member
Re: DateTimePicker, display MMM-yy only
Hi thanks for the replies,
I have set the custom format to "MMM-yy"
But I get the error
"Year, Month, and Day parameters describe an un-representable DateTime."
If I change the format to "dd-MMM-yy" it works.
??
-
Jun 30th, 2007, 06:31 PM
#5
Re: DateTimePicker, display MMM-yy only
I'll tell you one thing that really does bother me: when people ask for help, then others ask questions to clarify the situation in order to answer that question and they get ignored. ntg asked a question:
How do you change the month in code?
Please answer it. I have tested your situation and I get no such error, so it must have something to do with how you're setting the date. Either you're just plain doing it wrong or it only applies to some specific date or dates. Either way, we need to know EXACTLY what you're doing when the error occurs, i.e. what code you're executing and what values your variables have at that point.
-
Jun 30th, 2007, 06:56 PM
#6
Thread Starter
Member
Re: DateTimePicker, display MMM-yy only
Sorry, didn’t mean to offend anyone.
Not sure what was meant by the question “How do you change the month in code”
I am changing the month with the DateTimePicker.
No code is being executed when I get the error.
When the variable for the DateTimePicker is “” the date defaults to Jun-07. I have noticed I get the error when the month is changed and gets to “Jan”.
If the DateTimePicker has a variable already saved to it eg “May-07” I don’t get the error when I change the date. It only seems to happen when the variable is “”.
-
Jun 30th, 2007, 07:02 PM
#7
Re: DateTimePicker, display MMM-yy only
If you're using a variable to assign a value to the datetimepicker, that's what I mean by "in code". Can you post the exact code you're using?
-
Jun 30th, 2007, 07:16 PM
#8
Thread Starter
Member
Re: DateTimePicker, display MMM-yy only
The Variables for the DatetimePickers are "" until the DateTimePicker is set and saved for the first time.
If the variable is saved as "Jan-00" I will get the error or when the DateTimePicker is adjusted when the variable is "".
vb.net Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim y As Integer = 0
Me.ComboBox2.Text = Nothing
Me.ComboBox3.Text = Nothing
Me.ComboBox4.Text = Nothing
Me.ComboBox5.Text = Nothing
Me.ComboBox6.Text = Nothing
For i As Integer = 0 To IbIDList.Count - 1
y = i
If IbSymbolList(i) = Me.ComboBox1.SelectedItem Then
i = IbIDList.Count - 1
End If
Next i
Me.ComboBox2.SelectedItem = IbExchList(y)
Me.ComboBox3.SelectedItem = SecTypeList(y)
Me.ComboBox4.SelectedItem = TimeZoneList(y)
Me.ComboBox5.SelectedItem = ShowList(y)
Me.ComboBox6.SelectedItem = CurrencyList(y)
Me.DateTimePicker1.Text = SpotMonthList(y)
Me.DateTimePicker2.Text = NextExpList(y)
Me.DateTimePicker3.Text = LTDSpotMonthList(y)
Me.DateTimePicker4.Text = LTDNextExpList(y)
Me.DateTimePicker5.Text = DayOpenTimeList(y)
Me.DateTimePicker6.Text = DayMocExitTimeList(y)
Me.btSave.Enabled = False
End Sub
-
Jun 30th, 2007, 07:32 PM
#9
Re: DateTimePicker, display MMM-yy only
I'm having trouble understanding what "the variable" is referring to. The listing you've provided doesn't really help since there are several calls to methods with bodies that aren't included.
-
Jun 30th, 2007, 09:23 PM
#10
Re: DateTimePicker, display MMM-yy only
The simple fact is that you should NEVER be setting the Text property of a DateTimePicker control. You should be assigning a Date object to the Value property of the DateTimePicker and then the control does the formatting for you.
-
Jul 1st, 2007, 05:01 AM
#11
Thread Starter
Member
Re: DateTimePicker, display MMM-yy only
I have set the format to MMM-yyyy and no longer get the error.
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
|