"GoToPage" does not work in my project, which was created by vs2010 + CRforVS_13_0_13.exe (which was downloaded from http://scn.sap.com/docs/DOC-7824). change CRforVS_13_0_13.exe to CRforVS_13_0_16.exe still cannot fix this problem:
Please see below for my project information.
1. Create a C++ project, using "CMultiDocTemplate* pTemplate = LoadCRViewer_CFormView(&theApp);" to display project.
BOOL CMFC04App::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
{
delete pMainFrame;
return FALSE;
}
m_pMainWnd = pMainFrame;
// call DragAcceptFiles only if there's a suffix
// In an MDI app, this should occur immediately after setting m_pMainWnd
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line. Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
// Loading the MFC Extension dll
CMultiDocTemplate* pTemplate = LoadCRViewer_CFormView(&theApp);
return TRUE;
}
2. Create the other project, add report dialog information into .rc file.
IDD_CRYSTALREPORTVIEWER DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | WS_CHILD
EXSTYLE WS_EX_OVERLAPPEDWINDOW | WS_EX_ACCEPTFILES
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL "",IDC_CRVIEWER,"Static",SS_GRAYRECT | NOT WS_VISIBLE,7,7,306,186
END
3. Add method in related .cpp file, so that we can use this method in step 1.
extern "C" AFX_EXT_API CMultiDocTemplate* WINAPI LoadCRViewer_CFormView(CWinApp* pApp)
{
// Register the doc templates we provide to the app
//CWinApp* pApp = AfxGetApp();
if(pApp) {
ASSERT(pApp != NULL);
CMultiDocTemplate* pTemplate = new CMultiDocTemplate(IDR_CRVIEWER,
RUNTIME_CLASS(CDummyDoc),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CCrystalReportViewer));
pApp->AddDocTemplate(pTemplate);
pTemplate->OpenDocumentFile(NULL);
return pTemplate;
}
return NULL;
}
4. Load crystal report in .cpp file.
void CCrystalReportViewer::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
CString reportName = L"rassdk://" + GetAppPath() + L"\\View.rpt";
CString databastLocation = GetAppPath() + L"\\schedules.mdb";
ShowCrystalReport(reportName,databastLocation);
SetCRViewerWin(this);
// start up resizing, and do initial one.
m_okToResizeIt = true;
RestoreSize();
}
void CCrystalReportViewer::ShowCrystalReport(CString &reportName, CString &databaseLocation)
{
CrystalDecisions::CrystalReports::Engine::ReportDocument^ reportDocument1 = (gcnew CrystalDecisions::CrystalReports::Engine::ReportDocument());
reportDocument1->FileName = gcnew System::String(reportName);
CrystalDecisions::CrystalReports::Engine::Database^ database = reportDocument1->Database;
CrystalDecisions::CrystalReports::Engine::Tables^ databaseTables = database->Tables;
CrystalDecisions::Shared::ConnectionInfo^ connectionInfo = (gcnew CrystalDecisions::Shared::ConnectionInfo());
connectionInfo->ServerName = gcnew System::String(databaseLocation);
CrystalDecisions::CrystalReports::Engine::Table^ databaseTable = databaseTables[0];
CrystalDecisions::Shared::TableLogOnInfo^ tableLogonInfo = databaseTable->LogOnInfo;
tableLogonInfo->ConnectionInfo = connectionInfo;
databaseTable->ApplyLogOnInfo(tableLogonInfo);
//
// m_CRViewerControl
//
m_CRViewerControl->ActiveViewIndex = 0;
m_CRViewerControl->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
m_CRViewerControl->Dock = System::Windows::Forms::DockStyle::Fill;
m_CRViewerControl->Location = System::Drawing::Point(0, 0);
m_CRViewerControl->Name = L"CrystalReportViewer";
m_CRViewerControl->ReportSource = reportDocument1;
CRect rect;
GetClientRect(&rect);
m_CRViewerControl->Size = System::Drawing::Size(rect.Width(), rect.Height());
m_CRViewerControl->TabIndex = 0;
m_CRViewerControl->PageChanged += gcnew EventHandler(crystalReportViewer1_PageChanged);
m_CRViewerControl->Navigate += gcnew CrystalDecisions::Windows::Forms::NavigateEventHandler(Navigate_To);
m_CRViewerControl->Show();
}
- Open the solution with vs2005 (if you a higher compiler, you can upgrade the solution).
- First build project “CRViewer” and then “MFC04”.
- Run the project, a crystal report will be popup.
- Change page to “2” and then press enter key, report does not go to page 2 (GoToPage problem.png).
"GoToPage" only does not work in this project, if I create a winform project to load crystal report, no problem for "GoToPage". What’s wrong with “GoToPage” in my project?