Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Data Grid problem

Data Grid problem

Scheduled Pinned Locked Moved C#
helpcssvisual-studio
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Janu_M
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • J Janu_M

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      B 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        B Offline
        B Offline
        blakey404
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • B blakey404

          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

          J Offline
          J Offline
          Janu_M
          wrote on last edited by
          #4

          Thank you for your reply. I dont know how to use invoke. If you know any links regarding the invoke and triggering events please provide them to me. Thanks in Advance Thanks and Regards Ramu

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups