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. Adding Data to datagridview [modified]

Adding Data to datagridview [modified]

Scheduled Pinned Locked Moved C#
questiondata-structuresdebugging
3 Posts 2 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.
  • L Offline
    L Offline
    ldsdbomber
    wrote on last edited by
    #1
          do
                {
                    iniText = iniStream.ReadLine();
                    // Skip comments started by \* character
                    if(String.Compare(iniText.Substring(0,1),("\*")) == 0)
                        continue;
    
                    string \[\] dataItems = iniText.Split(new Char \[\] {','});
    
                    
                    dataGridView1.Rows.Add(dataItems);
    
    
                } while (iniText != null);
    

    When stepping through the code, dataItems correctly contains each array of comma separated variables, but the datagrid control is not being populated with the Rows.Add method. What am I missing? t.i.a OK, I changed it to this

                do
                {
                    iniText = iniStream.ReadLine();
                    if (iniText == null)
                        continue;
                    // Skip comments started by \* character
                    if(String.Compare(iniText.Substring(0,1),("\*")) == 0)
                        continue;
    
                    string \[\] dataItems = iniText.Split(new Char \[\] {','});
    
                    dataGridView1.Rows.Add(dataItems);
    
                } while (iniText != null);
    

    obviously I need to rethink my loop logic. But when i step through in Debug with F5 it populates the control properly, when I run without debugging, it is still empty. Why does that happen?

    modified on Wednesday, October 14, 2009 2:42 AM

    OriginalGriffO 1 Reply Last reply
    0
    • L ldsdbomber
            do
                  {
                      iniText = iniStream.ReadLine();
                      // Skip comments started by \* character
                      if(String.Compare(iniText.Substring(0,1),("\*")) == 0)
                          continue;
      
                      string \[\] dataItems = iniText.Split(new Char \[\] {','});
      
                      
                      dataGridView1.Rows.Add(dataItems);
      
      
                  } while (iniText != null);
      

      When stepping through the code, dataItems correctly contains each array of comma separated variables, but the datagrid control is not being populated with the Rows.Add method. What am I missing? t.i.a OK, I changed it to this

                  do
                  {
                      iniText = iniStream.ReadLine();
                      if (iniText == null)
                          continue;
                      // Skip comments started by \* character
                      if(String.Compare(iniText.Substring(0,1),("\*")) == 0)
                          continue;
      
                      string \[\] dataItems = iniText.Split(new Char \[\] {','});
      
                      dataGridView1.Rows.Add(dataItems);
      
                  } while (iniText != null);
      

      obviously I need to rethink my loop logic. But when i step through in Debug with F5 it populates the control properly, when I run without debugging, it is still empty. Why does that happen?

      modified on Wednesday, October 14, 2009 2:42 AM

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      I agree your loop logic needs some work, but in both original form and the modified form below it works fine either debugged or run as release version. Without seeing the rest of your code, I can only assume the difference is path related - is the file you are reading relative to the debug code folder and thus not available in the release version?

              string\[\] lines = File.ReadAllLines(@"C:\\XXTemp\\new.txt");
              foreach (string line in lines)
                  {
                  if (!line.StartsWith("\*"))
                      {
                      // Not a comment - they start with \*
                      dataGridView1.Rows.Add(line.Split(','));
                      }
                  }
      

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      L 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        I agree your loop logic needs some work, but in both original form and the modified form below it works fine either debugged or run as release version. Without seeing the rest of your code, I can only assume the difference is path related - is the file you are reading relative to the debug code folder and thus not available in the release version?

                string\[\] lines = File.ReadAllLines(@"C:\\XXTemp\\new.txt");
                foreach (string line in lines)
                    {
                    if (!line.StartsWith("\*"))
                        {
                        // Not a comment - they start with \*
                        dataGridView1.Rows.Add(line.Split(','));
                        }
                    }
        

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        L Offline
        L Offline
        ldsdbomber
        wrote on last edited by
        #3

        Thanks. Of course, that is exactly what it was, I hadn't changed the file read section to allow the user to browse for an actual file location! doh! thanks for the heads up

        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