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. populate a listview

populate a listview

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 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.
  • R Offline
    R Offline
    RIPOUX
    wrote on last edited by
    #1

    hi all i'm a newbie in programming so there is some "basic thing/way/how-it-should-be-wrote in coding" i still try to catch so please be patient :sigh: i'm trying to populate a listview with a .csv file a i just dont catch how to put it in string to add it. I already find how read the file, take one line at the time but thats it. From this point, i'm lost. anyone ready to help ? Thanks :)

    J R 2 Replies Last reply
    0
    • R RIPOUX

      hi all i'm a newbie in programming so there is some "basic thing/way/how-it-should-be-wrote in coding" i still try to catch so please be patient :sigh: i'm trying to populate a listview with a .csv file a i just dont catch how to put it in string to add it. I already find how read the file, take one line at the time but thats it. From this point, i'm lost. anyone ready to help ? Thanks :)

      J Offline
      J Offline
      Joseph Guadagno
      wrote on last edited by
      #2

      // Adds a new item
      listView1.Items.Add("");

      Where listView1 is the name of the listview control.

      Hope this helps! Joseph Guadagno http://www.josephguadagno.net

      G 1 Reply Last reply
      0
      • J Joseph Guadagno

        // Adds a new item
        listView1.Items.Add("");

        Where listView1 is the name of the listview control.

        Hope this helps! Joseph Guadagno http://www.josephguadagno.net

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        That will add empty string to the listview and a newbie might think that nothing is added. You can use either listview1.Add to add a single element or listview1.AddRange Both have overloads so I suggest you have a look at them :)

        R 1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          That will add empty string to the listview and a newbie might think that nothing is added. You can use either listview1.Add to add a single element or listview1.AddRange Both have overloads so I suggest you have a look at them :)

          R Offline
          R Offline
          RIPOUX
          wrote on last edited by
          #4

          thanks guys, i'm gonna look for this right now :)

          1 Reply Last reply
          0
          • R RIPOUX

            hi all i'm a newbie in programming so there is some "basic thing/way/how-it-should-be-wrote in coding" i still try to catch so please be patient :sigh: i'm trying to populate a listview with a .csv file a i just dont catch how to put it in string to add it. I already find how read the file, take one line at the time but thats it. From this point, i'm lost. anyone ready to help ? Thanks :)

            R Offline
            R Offline
            RIPOUX
            wrote on last edited by
            #5

            ok, i'm gonna try to be more specific, i think i missed something check this out please and tell me what i didn't do right there is my .csv file 3,One,Two,Three,Four,Five,Six,Seven,Eight, 0,5/19/2007 6:21:02 PM,A,B,C,777,,,, 1,5/19/2007 6:20:59 PM,A,B,C,666,,,, 2,5/19/2007 6:20:57 PM,A,B,C,555,,,, string[] Entier; string[] Colonnes; Entier = File.ReadAllLines("pdg.csv"); foreach (string CurrentLine in Entier) { Colonnes = CurrentLine.Split(new Char[] { ',' }); foreach (string CurrentCol in Colonnes) { ListViewItem item1 = new ListViewItem(CurrentCol); item1.SubItems.Add(Unit); listView1.Items.Add(item1); } } and there is my code. as you see i can read the file, can read only one line, can read one "item" in the line but i just dont know how to take all those parts and put it in my listview. something i just dont catch :(

            J 1 Reply Last reply
            0
            • R RIPOUX

              ok, i'm gonna try to be more specific, i think i missed something check this out please and tell me what i didn't do right there is my .csv file 3,One,Two,Three,Four,Five,Six,Seven,Eight, 0,5/19/2007 6:21:02 PM,A,B,C,777,,,, 1,5/19/2007 6:20:59 PM,A,B,C,666,,,, 2,5/19/2007 6:20:57 PM,A,B,C,555,,,, string[] Entier; string[] Colonnes; Entier = File.ReadAllLines("pdg.csv"); foreach (string CurrentLine in Entier) { Colonnes = CurrentLine.Split(new Char[] { ',' }); foreach (string CurrentCol in Colonnes) { ListViewItem item1 = new ListViewItem(CurrentCol); item1.SubItems.Add(Unit); listView1.Items.Add(item1); } } and there is my code. as you see i can read the file, can read only one line, can read one "item" in the line but i just dont know how to take all those parts and put it in my listview. something i just dont catch :(

              J Offline
              J Offline
              Joseph Guadagno
              wrote on last edited by
              #6

              The listview control uses an item a the "main" object in its collection. Each item has a collection of subitems. The easiest way to understand it is by opening up Windows Explorer and setting the view to list. You will see a file (item) with it's properties (subitems) like size, date, etc. There is an article on MSDN that provides clear examples. http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.items(VS.71).aspx

              Hope this helps! Joseph Guadagno http://www.josephguadagno.net

              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