Data Grid problem
-
Hi I am developing a windows application (VS 2003) in which it contains some buttins and a grid. The Grid has to show all the data from a csv file, for this i am reading all the data from csv file into datatable and giving that datatable as a datasource to data grid. dtTable = new DataTable(); dtTable.Columns.Add("Name"); dtTable.Columns.Add("Time1"); dtTable.Columns.Add("Time2"); dtTable.Columns.Add("Path"); dtTable.Columns.Add("IconName"); dtTable.AcceptChanges(); if(File.Exists(Application.StartupPath + "\\Recordings.csv")) { StreamReader sreader = new StreamReader(Application.StartupPath + "\\File.csv"); string strval = sreader.ReadLine(); while (strval != null) { DataRow row1 = dtTable.NewRow(); string[] str = strval.Split(','); for(int i = 0; i < str.Length; i++) { row1[i] = str[i]; } dtTable.Rows.Add(row1); strval = sreader.ReadLine(); } dtTable.AcceptChanges(); sreader.Close(); // } dtGrid.DataSource = dtTable; dtGrid.Refresh(); I am using the above code for showing the contents of file to Grid. if user clicks start button on the form, after completing the action i want to add a row to grid. For this i am writing the new row to the CSV file and calling the above code. But it is giving error: "Controls created on one thread cannot be parented to a control on a different thread." Any one please help me. Thanks in Advance
-
Hi I am developing a windows application (VS 2003) in which it contains some buttins and a grid. The Grid has to show all the data from a csv file, for this i am reading all the data from csv file into datatable and giving that datatable as a datasource to data grid. dtTable = new DataTable(); dtTable.Columns.Add("Name"); dtTable.Columns.Add("Time1"); dtTable.Columns.Add("Time2"); dtTable.Columns.Add("Path"); dtTable.Columns.Add("IconName"); dtTable.AcceptChanges(); if(File.Exists(Application.StartupPath + "\\Recordings.csv")) { StreamReader sreader = new StreamReader(Application.StartupPath + "\\File.csv"); string strval = sreader.ReadLine(); while (strval != null) { DataRow row1 = dtTable.NewRow(); string[] str = strval.Split(','); for(int i = 0; i < str.Length; i++) { row1[i] = str[i]; } dtTable.Rows.Add(row1); strval = sreader.ReadLine(); } dtTable.AcceptChanges(); sreader.Close(); // } dtGrid.DataSource = dtTable; dtGrid.Refresh(); I am using the above code for showing the contents of file to Grid. if user clicks start button on the form, after completing the action i want to add a row to grid. For this i am writing the new row to the CSV file and calling the above code. But it is giving error: "Controls created on one thread cannot be parented to a control on a different thread." Any one please help me. Thanks in Advance
You need to always deal with your controls in your main thread.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You need to always deal with your controls in your main thread.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
use an event to trigger the creation of your control on the main thread, or use this.InvokeRequired to force you control to be created on the main thread