locked
DataGrid + threading help - 'Controls created on one thread cannot be parented to a control on a different thread.'

    Question

  • Im having trouble with threading, I have a DataGrid, and im downloading data from a server in a new thread. Once the data is downloaded I bind my arrayList to my DataGrid and create my DataGridTableStyle and add it to my DataGrid.

    When i run my app it crashes saying 'Controls created on one thread cannot be parented to a control on a different thread.'

    Here some code:

     

    Thread myThread=new Thread(new ThreadStart(readMessages));
    myThread.Start();

     


    private void readMessages()
    {
        // load messages from server
        ...

        // once messages loaded

        dataGridMessages.DataSource = arrayListDataGridMessages;
        DataGridTableStyle ts = new DataGridTableStyle(); // crashing here
        ...
    }

     

    Any ideas because im completly stuck. Thanks.

     

    Wednesday, August 23, 2006 4:46 PM

Answers

All replies