By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,449 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,449 IT Pros & Developers. It's quick & easy.

Reading a ListView item

P: n/a
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

Jul 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ray Mitchell wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Jul 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.