Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Datagrid (.Net) exception when i hit CTRL+C

  • 03-08-2004 04:11PM
    #1
    Registered Users, Registered Users 2 Posts: 2,758 ✭✭✭


    Folks,

    Like it says above...

    When i hit Control C in a datagrid on my for i get an exception which boils down to [see attached file].

    It doesn't happen when i hit Ctrl + A/ CTRL + V / CTRL + X etc.

    The grid is bound to a DataView which has its AllowEdit/AllowDelete/AllowNew set to false. Its the standard datagrid that comes with .Net. Also i'm not multithreading so i don't know why its giving me a threading exception.

    I've googled and no results that help me out any.

    Any help would dig me out of a hole lads...Thanks!


Comments

  • Registered Users, Registered Users 2, Paid Member Posts: 2,427 ✭✭✭ressem


    By default, a windows App created using visual studio will have the attribute
    [STAThread]
    immediately prior to Main.

    Adding it back in will stop this exception from appearing.

    Ctrl-C seems to make a call to System.Reflection that Ctrl X doesn't.

    http://www.syncfusion.com/faq/winforms/search/967.asp
    "
    While the STAThread is required (as the documentation states) and pertinent only to applications that use COM interop, 1.0 version of the .Net framework has some bugs that makes it necessary for you to specify the STAThread attribute:

    1) Ole Drag Drop will not work without STA. You can check this by turning on drag and drop in a form and try to run it.

    2) Invoking a method in a type using Reflection will not work either.
    "

    They say on that page that this is a bug that was sorted on framework 1.1, but apparently not.



    For those more informed than me
    Exception at
    StackTrace " at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy)\r\n at System.Windows.Forms.Clipboard.SetDataObject(Object data)\r\n at System.Windows.Forms.DataGrid.ProcessDialogKey(Keys keyData)\r\n at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)\r\n at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)\r\n at System.Windows.Forms.Control.PreProcessMessage(Message& msg)\r\n at System.Windows.Forms.ThreadContext.System.Windows.Forms.UnsafeNativeMethods+IMsoComponent.FPreTranslateMessage(MSG& msg)\r\n at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n


    Message "The current thread must set to Single Thread Apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."


Advertisement