on 06-25-2008 8:02 PM
Hi.
Can help me with this please:
How can I open a CrystalReportViewer in my project SDK. Because I have this problem when my applications debugins this open the Viewer with the report. But when my report is created with parameters this show this error.
activex control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment
Regards,
Jose
Hi Jose,
If you are working in .NET environment, you can try adding "[STAThread]" before main() like:
[[STAThread]]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Best Regards,
Jay.
Edited by: Jay Ji on Jun 26, 2008 11:39 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Jay. Thanks for your help.
I find this problem:
When in my addon I have a event that open the report this show the error. But when I open the report outsite the event this is fine.
THIS IS MY CODE:
Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)handles SBO_Application.MenuEvent
Dim openR as new Report
openR.ShowDialog()
End Sub
How can I use your code?
Regards,
Jose
I use your code in my event but still show the message.
This is this the code of the event:
Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New OpenReport)
End Sub
But if I use a report without parameter this working fine.
What can I do?
Regards,
Jose
Hi,
From your catching event , you need to open a single thread like that:
Imports System.Threading
Item Event Sub:
Dim thread As Thread = New Thread(New ThreadStart(AddressOf CallingDialog))
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
End Sub
Private Sub CallingDialog()
Dim MyWindow As WindowWrapper = Nothing
Dim MyProcs() As Process
MyProcs = Process.GetProcessesByName("SAP Business One")
If MyProcs.Length = 1 Then
MyWindow = New WindowWrapper(MyProcs(0).MainWindowHandle)
End If
FileDialog = New System.Windows.Forms.OpenFileDialog
FileDialog.ShowDialog(MyWindow)
End Sub
the WindowWrapper will open the FileDailog in the front and not in the background.
Moti.
Hi Jose,
You can write the CallingDialog function without window wrapper patch:
Private Sub CallingDialog()
FileDialog = New System.Windows.Forms.OpenFileDialog
FileDialog.ShowDialog
End Sub
About your question , if you have problem with the appearance of the FileDilaog, add this class of window wrapper:
Public Class WindowWrapper
Implements System.Windows.Forms.IWin32Window
Private _hwnd As IntPtr
Public Sub New(ByVal handle As IntPtr)
_hwnd = handle
End Sub
Public ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
Get
Return _hwnd
End Get
End Property
End Class
Moti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
I have the same scenario. I have applied the code given above but to me the problem remains the same.
For your reference I copy my code here:
Module MainSub
Public Sub main()
Dim thread As Thread = New Thread(New ThreadStart(AddressOf CallingCode))
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
Dim AJMReports As reports
AJMReports = New reports()
System.Windows.Forms.Application.Run()
End Sub
Private Sub CallingCode()
Dim Filedialog As Printouts
Filedialog = New Printouts
Filedialog.ShowDialog()
End Sub
End Module
"Printouts" above is my vb.net form to show crystal reports.
Can anybody guide me where I am doing wrong?
Many thanks in advance for any help.
User | Count |
---|---|
98 | |
12 | |
10 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.