tags:

views:

36

answers:

4

Hello

Im working with ListView in C#.NET.

Im using code similar to this:

string[] row1 = { "s1", "s2", "s3" };
listView1.Items.Add("Column1Text").SubItems.AddRange(row1);

However I can't see the content, only the name of the column. Why is this?

A: 

It looks like you're adding subitems. I don't know what columns you're showing, but the first column will be the item text itself, with further columns being the subitems.

So, if I want to show A B C, I need to add an item of A with two subitems of B and C. That will show all three. If you want to see all three in your example, do an Items.Add on each one. They'll all fill the first column.

Ari Roth
A: 

Try something like this:

 ListViewItem item = new ListViewItem("Column1Text"); 
 item.SubItems.AddRange(row1); 
 listView1.Items.Add(item);
 listView1.View = View.Details;
Kyle Rozendo
well I think I found the problem...I didnt create columnHeaders...before...if I want to add another array (row2) for another row..? I tried: ListViewItem item = new ListViewItem("Co1"); item.SubItems.AddRange(row1); listView1.Items.Add(item); ListViewItem item1 = new ListViewItem("Co2"); item.SubItems.AddRange(row2); listView1.Items.Add(item1); listView1.View = View.Details;but Im not getting the data in the in Item1 but in Item..? any idea what Im doing wrong?Ty!! ^_^)
YoniGeek
A: 

well I think I found the problem...I didnt create columnHeaders...before.if I want to add another array (row2) for another row..? I tried:

ListViewItem item = new ListViewItem("Co1"); item.SubItems.AddRange(row1); listView1.Items.Add(item);
 ListViewItem item1 = new ListViewItem("Co2"); 
item.SubItems.AddRange(row2); listView1.Items.Add(item1); 
listView1.View = View.Details; 

but Im not getting the data in the in Item1 but in Item..? any idea what Im doing wrong? Ty!! ^_^)

YoniGeek
A: 

More comment to the answer: Never-mind! I fixed it!! Ty kyle to gave the idea to check the column Headers...

Now I got a new questions

....I added some columnheaders to the listview inthis case where it's very simple BUT if I'm getting arrays with different sizes...Is it any way how I can make this columnHeaders changing, adding more column Headers in case the size increase or decrease? (writing some code maybe)

Gracias!

YoniGeek
Hey Yoni, welcome to SO. You should create a new question for any different questions and edit your initial question instead of adding new answers.
Kyle Rozendo