populate a listview
-
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 :)
-
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 :)
// 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
-
// 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
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 :)
-
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 :)
-
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 :)
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 :( -
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 :(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