Skip to Content
author's profile photo Former Member
Former Member

Problem open report

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 26, 2008 at 09:39 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2008 at 06:43 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.