Reputation: 483
I have two columns in my listView, lets call them Column1, and Column2.
Is it possible to add a bunch of items to column1 only, and make it so those items only go strictly under column1 and not column2?
When I add items it adds an item to Column1, and then Column2 and I don't want that.
How would I go about doing this?
Here's some of my test code. I made an array with two strings. I want both of those strings to go under column1 (each in their own row) and not under column2. When I test it, they still go under column1 AND column2 which is what I don't want.
string[] h = {"Hi","Hello"};
listViewGoogleInsight.Items.Add(new ListViewItem(h));
Upvotes: 3
Views: 7522
Reputation: 8656
Maybe this will help:
string[] h = {"Hi","Hello"};
foreach(string s in h) //this in case when you have more that two strings in you array
listViewGoogleInsight.Items.Add(new ListViewItem(s));
In your code you are passing a string array to the constructor of a ListViewItem
which is creating one ListViewSubitem of the "Hello". You should add each string separately.
EDIT: After your request to add only to column2 you can do it like this. You must pass empty string to for the first column because you need to make a ListViewItem for the first column and additional ListViewSubitems for every other column.
string[] h = { "Hi", "Hello" };
int count=0;
foreach (string s in h) //this in case when you have more that two strings in you array
{
ListViewItem lvi = listView1.Items[count++];
lvi.SubItems.Add(s);
listView1.Items.Add(lvi);
}
Upvotes: 1