This is a migrated thread and some comments may be shown as answers.

Multiview calendar show 1 full year help needed

5 Answers 148 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 25 Mar 2011, 08:51 PM
Hey all,

I have a multiview calendar that has 6 columns and 2 rows and I need to show January as the first month and December as the last month (for any selected year). I have set the rangemin to January 1st (selected year) and the rangemax to December 31st (selected year), however this does not cause January to be the first month, the first month is whatever the current month is (in this case March). So I tried setting the focusdate to January 1st (selected year) and that works, however it causes the calendar to look like January 1st is selected, which causes confusion because the user is looking at all of their scheduled working days for the year. I've tried to reset the focusdate to another date (that is a working day, thereby "hiding" the focusdate) within the selected year and that seems to work, however it seems like a workaround and I'm wondering if there is a better way to do what I'm doing.

I would think there is an easy way to set the first/last displayed month without having to set the focusdate. If anyone knows how to do this please let me know.

Also, how do I get rid of the border around today's date?

Thanks!

edit: Tried this, CalendarElement.Calendar.DefaultView.ViewStartDate = "1/1/" & GoalYear but that doesn't work either.

edit2: The above code allows me to click on the calendar header and then I can see that "View" and select it, however I need it auto selected of course

edit3: Ok, I'm seeing really weird behavior. I'm attaching 3 screenshots to show, but basically when the form loads the header says "January 2011-December 2011", however the calendar's start at March 2011 (screenshot 1). When I click on the header I get 2? view options, "January 2011-December 2011" and "December 2011-November 2012" (screenshot 2). If I select "January 2011-December 2011" (which is what I want it to load as) then the result is screenshot 3, which is correct.

5 Answers, 1 is accepted

Sort by
0
Josh
Top achievements
Rank 1
answered on 26 Mar 2011, 04:04 AM
Here is the code I'm using:

 

 

For Each oPageView As UI.RadPageViewPage In rpvProducers.Pages

 

 

 

 

Dim oucProducerGoal As ucProducerGoals = oPageView.Controls("ucProducerGoals")

 

 

oucProducerGoal.calWorkingDays.SelectedDates.Clear()

 

oucProducerGoal.calWorkingDays.CalendarElement.Calendar.DefaultView.ViewStartDate =

 

"1/1/" & GoalYear

 

 

oucProducerGoal.calWorkingDays.CalendarElement.Calendar.DefaultView.ViewEndDate =

 

"12/31/" & GoalYear

 

 

oucProducerGoal.calWorkingDays.FocusedDate =

 

"1/1/" & GoalYear

 

 

oucProducerGoal.calWorkingDays.RangeMinDate =

 

"1/1/" & GoalYear

 

 

oucProducerGoal.calWorkingDays.RangeMaxDate =

 

"12/31/" & GoalYear

 

 

oucProducerGoal.txtDailyGoal.Text = FormatCurrency(0)

 

cdvGoalDays.RowFilter =

 

"GoalID = '" & cdvGoals(0)("GoalID").ToString & "' And PersonID = '" & oPageView.Tag.ToString & "'"

 

 

 

If cdvGoalDays.Count > 0 Then

 

cdvProduction.RowFilter =

 

"ProducerID = '" & oPageView.Tag.ToString & "' And Date >= '1/1/" & GoalYear & " 00:00:00' And Date <= '12/13/" & GoalYear & " 23:59:59'"

 

oucProducerGoal.txtDailyGoal.Text = FormatCurrency(cdvGoalDays(0)(

 

"DailyGoal"))

 

 

 

 

Dim dteWorkDays(cdvProduction.Count - 1) As Date

 

 

 

Dim iDays As Integer = 0

 

 

 

 

For Each drvProduction As DataRowView In cdvProduction

 

 

dteWorkDays(iDays) = drvProduction(

 

"Date")

 

 

iDays += 1

 

 

 

'oucProducerGoal.calWorkingDays.SelectedDate = drvProduction("Date")

 

 

 

'oucProducerGoal.calWorkingDays.FocusedDate = drvProduction("Date")

 

 

 

'Application.DoEvents()

 

 

 

'oucProducerGoal.calWorkingDays.Refresh()

 

 

 

Next

 

 

 

'oucProducerGoal.calWorkingDays.FocusedDate = dteWorkDays(0)

 

oucProducerGoal.calWorkingDays.SelectedDates.AddRange(dteWorkDays)

oucProducerGoal.calWorkingDays.Refresh()

 

 

End If

 

 

 

Next

 

0
Emanuel Varga
Top achievements
Rank 1
answered on 26 Mar 2011, 06:17 PM
Hello,

The property you should use is CurrentViewColumn, you can read more about these properties here.
VB code:
Private Function GetCalendarForYear(year As Integer) As RadCalendar
    Dim calendar = New RadCalendar()
    calendar.AllowMultipleView = True
    calendar.MultiViewColumns = 6
    calendar.MultiViewRows = 2
    calendar.RangeMinDate = New DateTime(year, 1, 1)
    calendar.RangeMaxDate = New DateTime(year, 12, 31)
    Dim today = DateTime.Now
    Dim colForCurrentDate = If(today.Month <= 6, today.Month - 1, today.Month - 7)
    Dim rowForCurrentDate = If(today.Month <= 6, 0, 1)
    calendar.CurrentViewColumn = colForCurrentDate
    calendar.CurrentViewRow = rowForCurrentDate
    Return calendar
End Function

C# code:
private RadCalendar GetCalendarForYear(int year)
{
    var calendar = new RadCalendar();
    calendar.AllowMultipleView = true;
    calendar.MultiViewColumns = 6;
    calendar.MultiViewRows = 2;
    calendar.RangeMinDate = new DateTime(year, 1, 1);
    calendar.RangeMaxDate = new DateTime(year, 12, 31);
    var today = DateTime.Now;
    var colForCurrentDate = today.Month <= 6 ? today.Month - 1 : today.Month - 7;
    var rowForCurrentDate = today.Month <= 6 ? 0 : 1;
    calendar.CurrentViewColumn = colForCurrentDate;
    calendar.CurrentViewRow = rowForCurrentDate;
    return calendar;
}

Basically you want that if the current month is <= 6 then the currentViewColumn should be the currentmonth - 1 and the row 0 or else the current view column should be current month - 7 and row 1.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Josh
Top achievements
Rank 1
answered on 26 Mar 2011, 11:02 PM
Thanks Emanuel, still having problems though.

So I made a test project and copied your code in, and it works when loading up 2011, but try sending 2010 in as the year. When I do that I get October 2010 - September 2011. No matter how I try changing the code I cannot get this to work so any additional help you can provide is greatly appreciated.

Thanks!
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 28 Mar 2011, 08:32 AM
Hello again Josh,

If today is not in the desired interval you should set a focused date, here I've set the minimum date as the selected date.

Private Function GetCalendarForYear(year As Integer) As RadCalendar
    Dim calendar = New RadCalendar()
    calendar.AllowMultipleView = True
    calendar.MultiViewColumns = 6
    calendar.MultiViewRows = 2
    calendar.RangeMinDate = New DateTime(year, 1, 1)
    calendar.RangeMaxDate = New DateTime(year, 12, 31)
    Dim today = DateTime.Now
    Dim colForCurrentDate As Integer = 0, rowForCurrentDate As Integer = 0
    If today.Year = year Then
        colForCurrentDate = If(today.Month <= 6, today.Month - 1, today.Month - 7)
        rowForCurrentDate = If(today.Month <= 6, 0, 1)
    Else
        calendar.FocusedDate = calendar.RangeMinDate
    End If
 
    calendar.CurrentViewColumn = colForCurrentDate
    calendar.CurrentViewRow = rowForCurrentDate
    Return calendar
End Function

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Josh
Top achievements
Rank 1
answered on 28 Mar 2011, 08:45 PM
And there it is! Thanks so much Emanuel!
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Josh
Top achievements
Rank 1
Answers by
Josh
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or