hi..
i am fairly new to VB.Net and I have a form thats calling a crystal report. The report however takes a long time to load. i tried using Threads and I keep getting the following error : [ controls created on one thread cannot be parented to a control on another thread ] how can i solve this error. Any assistance is greatly appreciated
i am fairly new to VB.Net and I have a form thats calling a crystal report. The report however takes a long time to load. i tried using Threads and I keep getting the following error : [ controls created on one thread cannot be parented to a control on another thread ] how can i solve this error. Any assistance is greatly appreciated
Code:
Public docReport As New rptStatus Public invReport As New rptInventory Public useReport As New rptUser Public oReport As Object Public rType as String Private Sub frmReports_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If rType = "Inventory" Then oReport = invReport ElseIf rType = "Status" Then oReport = docReport Else oReport = useReport oReport.SetParameterValue(0, param3) oReport.SetParameterValue(1, param4) oReport.SetParameterValue(2, param1) oReport.SetParameterValue(3, param2) End If Dim repThread As New Thread(AddressOf loadReport) repThread.IsBackground = True repThread.Priority = ThreadPriority.Normal repThread.Start() End Sub Private Sub loadReport() Control.CheckForIllegalCrossThreadCalls = False cviewer.Visible = True Me.Cursor = Cursors.WaitCursor frmMain.tslCurrent.Text = "Loading Report ..." Application.DoEvents() Try Dim myTable As CrystalDecisions.CrystalReports.Engine.Table Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo For Each myTable In oReport.Database.Tables myLogin = myTable.LogOnInfo myLogin.ConnectionInfo.Password = strPass myLogin.ConnectionInfo.UserID = strUser myLogin.ConnectionInfo.ServerName = strServer myLogin.ConnectionInfo.DatabaseName = strDatabase myTable.ApplyLogOnInfo(myLogin) Next '******************ERROR OCCURS HERE ******************************* cviewer.ReportSource = oReport cviewer.ShowRefreshButton = False Catch ex As Exception MsgBox(ex.Message) frmMain.tslCurrent.Text = "Report not Loaded" Finally Me.Cursor = Cursors.Default 'frmMain.tslCurrent.Text = "" End Try End Sub
Comment