Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Calendar
  New Posts New Posts RSS Feed - How To switch back in day mode?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How To switch back in day mode?

 Post Reply Post Reply
Author
Message
prashant View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 February 2007
Location: India
Status: Offline
Points: 165
Post Options Post Options   Thanks (0) Thanks(0)   Quote prashant Quote  Post ReplyReply Direct Link To This Post Topic: How To switch back in day mode?
    Posted: 09 April 2008 at 9:32am
As per shown in the example I added multiple schedules. Now I want to switch back in Day mode/View. How to achieve this?
Back to Top
prashant View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 February 2007
Location: India
Status: Offline
Points: 165
Post Options Post Options   Thanks (0) Thanks(0)   Quote prashant Quote  Post ReplyReply Direct Link To This Post Posted: 10 April 2008 at 1:37am
Hi Oleg,

We have Day, 2 Days, Week, 2 Weeks, Month and Multi Schedule Views for Calendar.

Issue:
When we want to go back to "Day" View from "MultiShedule" View, View is not getting changed to DAY View and not getting displayed.

Thanks in advance.
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 01 May 2008 at 4:48pm

As you probably discovered there's no method illustrated in the samples to revert to the original "day view" mode after using a multiple configuration. However, it is possible.

What you need to do is recreate the original calendar resource. When you debug you can see that there is indeed a calendar resource created when you start in day view mode.  It has a blank string for name so it doesn't display anything at the top of the calendar.

Here is an example of using a new resource when switching to restore day view mode:

void CCalendarDoc::OnScheduleSelect()
{
    CSchedDlg dlg;
    int nDlgRes = (int)dlg.DoModal();
    if (nDlgRes == IDOK)
    {
        CXTPCalendarControl* pCalendar = GetCalendarCtrl();

        if ( dlg.m_pResources->GetCount() )
        {
            pCalendar->SetResources(dlg.m_pResources);
            pCalendar->Populate();
            pCalendar->RedrawControl();
        }
        else
        {
            CXTPCalendarResource *pResource = new CXTPCalendarResource(pCalendar);
            if (!pResource)
                ASSERT(FALSE);

            pResource->SetDataProvider(pCalendar->GetDataProvider());
            pResource->SetName(_T(""));
            pCalendar->GetResources()->Add(pResource);

            for (int i = 0; i < pCalendar->GetResources()->GetCount(); i++ )
            {
                if (pResource->GetName() != _T("") )
                    pCalendar->GetResources()->RemoveAt(i);
            }
        }
    }

There are probably other, better ways of doing this but this works. I tried a couple other approaches which failed and I'm not 100% sure why, but I believe it's due to the way smart pointers are used.

A couple of things to avoid:

1. GetResources->RemoveAll() will fail. 
2. Maintaining a copy of the original resource and trying to reuse it will fail and it's scarcely worth the effort.

Hope this helps you out. It takes some digging to see exactly what the system expects. Maybe CJ can include the methodology in their sample so others aren't stuck on this.




Back to Top
KumarCJ View Drop Down
Groupie
Groupie
Avatar

Joined: 02 April 2007
Location: India
Status: Offline
Points: 96
Post Options Post Options   Thanks (0) Thanks(0)   Quote KumarCJ Quote  Post ReplyReply Direct Link To This Post Posted: 23 July 2008 at 2:18am
Hi,
 
I have one doubt, I implemented two modes 1) Multischedule and 2) Day
 
In multischedule mode I can see newly added scedules (Columns) but when I try to switch back to Day mode Columns remains as it is.
 
My question is
 
How to remove schedules while switching back to Day mode?
 
I tried following code but CAlendar cntrol is turning whole RED
 
Code:-
 
CXTPCalendarControl* pCalendarCtrl = &this->GetCalendarCtrl();
CXTPCalendarData * pData = pCalendarCtrl->GetDataProvider();
if (!pData)
    return;
  
pSchedules = pData->GetSchedules();
  
  
if (!pSchedules)
     return;  
            

int iCnt = pCalendarCtrl->GetResources()->GetCount();  
// Here I am getting proper column/schedule count (2)
for (int i = 0; i < iCnt; i++ )
{
     pCalendarCtrl->GetResources()->RemoveAt(0);
}
 
Thanks in advance.
Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Posted: 25 July 2008 at 3:16am
Not 100% sure of what's going on based on your code, but I did not see in your code where you set the original provider again.

Set new (same as original) provider:

pCalendar->SetDataProvider(GetDataProvider(), FALSE);

where GetDataProvider() returns your original provider such as SQLDataProvider etc.

You have to set the new (old!) provider in order to repopulate.


Back to Top
AndreiM View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 18 August 2007
Status: Offline
Points: 132
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndreiM Quote  Post ReplyReply Direct Link To This Post Posted: 06 August 2008 at 2:42pm
Hello,
You are right.
CXTPCalendarControl::SetDataProvider is used to easy set a single resource.
CXTPCalendarControl::SetResources is used to set one or few resources.
 
Calendar is multi-scheduled in the kernel. There is no special single resource mode. 
If you set only one resource - it just does not show resource header (name) by default .
 
KumarCJ in his code remove all resources and does not add one.
 
GetDataProvider() simply return first resource data provider.
 
FYI. Each resource may have own separate data provider as far as one data provider may be used for many resources.
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.219 seconds.