Reading a ListView item

R

Ray Mitchell

Hello,

I have a ListView in which each item is an array of 5 strings. I add these
string arrays to the ListView by doing the following, where "result" is the
array of 5 strings to add:

listView.Items.Add(new ListViewItem(result));

Now I would like to read one of the items back into an array of 5 strings,
for instance, the array stored as ListView item 0. It seems that the
following would be the symmetrical way of doing it, but obviously it's not:

string [] s = (string [])listView.Items[0];

Of course I can always extract the 5 subitems one at a time into each
element of my string array, but that seems pretty brutal.

Thanks,
Ray
 
G

Göran Andersson

Ray said:
Hello,

I have a ListView in which each item is an array of 5 strings. I add these
string arrays to the ListView by doing the following, where "result" is the
array of 5 strings to add:

listView.Items.Add(new ListViewItem(result));

That doesn't put the array in the ListViewItem. The constructor loops
through the array and creates a subitem for each string in the array.
Now I would like to read one of the items back into an array of 5 strings,
for instance, the array stored as ListView item 0. It seems that the
following would be the symmetrical way of doing it, but obviously it's not:

string [] s = (string [])listView.Items[0];

Of course I can always extract the 5 subitems one at a time into each
element of my string array, but that seems pretty brutal.

Well, that's what you have to do. If you haven't kept the original
array, it doesn't exist any more. Only the separate string in the array
exists, one in each of the subitems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top