Adding radspreadsheet programaticlly to form

0 Answers 96 Views
PageView Spreadsheet
Benjamin
Top achievements
Rank 1
Benjamin asked on 10 Dec 2022, 11:46 PM | edited on 11 Dec 2022, 12:40 AM

        public void pastPanelInit()
        {

            var threadParameters = new ThreadStart(initSpreadSheet);
            var thread2 = new Thread(threadParameters);
            thread2.SetApartmentState(ApartmentState.STA);
            thread2.Start();
            //thread2.Join();

        }


        private void initSpreadSheet()
        {

            if (pastTabCalender.InvokeRequired)
            {
                pastTabCalender.Invoke(new Action(() => initSpreadSheet()));
            
            }
            else
            {
                spreadSheet = new RadSpreadsheet();
                spreadSheet.Dock = DockStyle.Fill;
                spreadSheet.Anchor = AnchorStyles.Top | AnchorStyles.Left;
                spreadSheet.Workbook.Worksheets.Add();
                pastTabCalender.Controls.Add(spreadSheet);
            }
        }

Im having some trouble adding a spreadsheet to my RadPageViewPage since the spreadsheet requires to be on a thread. This still gives me 'Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.'.

Is there anyone that could explain what im doing wrong here? Thanks.

 

Edit. Updated the code a bit and this gives me that it requires to be on the STA thread. Its something im not understanding with these threadings in c#.

Benjamin
Top achievements
Rank 1
commented on 11 Dec 2022, 01:48 AM


            var threadParameters = new ThreadStart(() => {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ExpressTransportForm());
            });
            var thread2 = new Thread(threadParameters);
            thread2.SetApartmentState(ApartmentState.STA);
            thread2.Start();
Solved it by just starting the application in STA. Feelsgoodman. Hope this helps others.

No answers yet. Maybe you can help?

Tags
PageView Spreadsheet
Asked by
Benjamin
Top achievements
Rank 1
Share this question
or