[RESOLVED] MonthCalendar problem
I have one more problem with MonthControl.
I have For...Next hanger.
And when I bold some dates the program doesn't show bold dates on month calendar.
When I move on next or previous month and get back to currently month the program normal displays bold dates. What's the problem?
Re: MonthCalendar problem
You're not being very descriptive.
Some code that generates the bold dates might help a bit.
Re: MonthCalendar problem
What is "For...Next hanger"?
As for the bolded dates problem, you need to call UpdateBoldedDates method after you add bolded date(s) to your MonthCalendar
Re: MonthCalendar problem
For...Next
Dim a As Integer
Dim b As Integer
For a = 1 To b
...
Next
Re: MonthCalendar problem
Quote:
Originally Posted by
hepeci
For...Next
Dim a As Integer
Dim b As Integer
For a = 1 To b
...
Next
So what is the problem with this loop? Your a and b variables are not initialized thus they get the default value of zero.
In the For loop, you set a = 1, but b is still 0, so the loop never runs any iteration. If you want to loop backwards, you have to explicitly code it
Code:
For a = 1 to b Step -1
....
Next
Re: MonthCalendar problem
Based on what I am reading, when you add bolded dates, the control is not refreshing until you move months, is that correct?
If so, did you try calling UpdateBoldedDates?
Re: MonthCalendar problem
Negative,thanks! :)
And one more thing, how to check is some date bold?
Re: MonthCalendar problem
BoldedDates is an array of bolded dates. You could use the Contains method to determine if a specific date is bolded or not.
Re: MonthCalendar problem
Actually I'm interested in how to check is selected date bold or not.
Re: MonthCalendar problem
So check to see if the BoldedDates contains the SelectionStart date.
Re: MonthCalendar problem
Just how Negative0 told you.
Re: MonthCalendar problem
Code:
lblDate.Text = MonthCalendar1.SelectionRange.Start
That's code for printing selected dates, this goes on _DateChanged event of MonthCalendar control, and how to check bold dates, actually is selected date bold or not?
Re: MonthCalendar problem
I think this is what they have told you
Code:
Private Sub MonthCalendar1_DateChanged(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) _
Handles MonthCalendar1.DateChanged
If MonthCalendar1.BoldedDates.Contains(MonthCalendar1.SelectionStart) Then
Stop
End If
End Sub
Re: MonthCalendar problem
This code doesn't work ('Contains' is not a member of 'System.Array') :(
Re: MonthCalendar problem
What version of the .Net Framework are you using?
Re: MonthCalendar problem
Re: MonthCalendar problem
Actually, your code will have to be something like this:
Code:
Dim boldDateList() As Date = MonthCalendar1.BoldedDates
For Each d As Date In boldDateList
If d.ToShortDateString = MonthCalendar1.SelectionStart.ToShortDateString Then
MessageBox.Show("True")
End If
Next
I realized that BoldedDates returns the selected Date *with* the current time appended to the end. Therefore, trying to compare SelectionStart with a BoldedDate item won't work. The dates may match but the times won't. So, you have to be able to shorten the date to just the date, which is done above.
Maybe there is a way to do it with BoldedDates, but I can't find one.
Re: MonthCalendar problem
Re: [RESOLVED] MonthCalendar problem
That means that you did something like this
Code:
MonthCalendar1.AddBoldedDate(#12/19/2009 08:00#)
instead of
Code:
MonthCalendar1.AddBoldedDate(#12/19/2009#)
Re: [RESOLVED] MonthCalendar problem
Quote:
Originally Posted by
dbasnett
That means that you did something like this
Code:
MonthCalendar1.AddBoldedDate(#12/19/2009 08:00#)
instead of
Code:
MonthCalendar1.AddBoldedDate(#12/19/2009#)
Well, true, I guess it depends on how you add the dates.
I was doing it like this:
Code:
MonthCalendar1.AddBoldedDate(Now.AddDay(-4))
MonthCalendar1.AddBoldedDate(Now())
MonthCalendar1.AddBoldedDate(Now.AddDay(3))
Re: [RESOLVED] MonthCalendar problem
If you would have added them like this you wouldn't have needed the additional code.
Code:
MonthCalendar1.AddBoldedDate(Now.AddDays(-4).Date)
MonthCalendar1.AddBoldedDate(Now().Date)
MonthCalendar1.AddBoldedDate(Now.AddDays(3).Date)
If MonthCalendar1.BoldedDates.Contains(MonthCalendar1.SelectionStart.Date) Then
Beep()
End If
So we worked around the OP's problem, but did we actually fix it?
Re: [RESOLVED] MonthCalendar problem
I guess it depends on how he is adding his dates and where he is getting them from. lol
Re: [RESOLVED] MonthCalendar problem
The OP never posted code for how the dates were being bolded. Well hopefully it is not one of those things that one wrong led to a kludge, that will lead to many more problems.