Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi in my program i add ListView SubItems to RichTextBox and it doesn't have problem for 2 SubItems but more than 2 it give me an error
This is My Problem[^]
What should i do?
With Respect
Posted

1 solution

In the 'for loop in the 'foreach loop replace slv.Items.Count with item.SubItems.Count
 
Share this answer
 
Comments
Avenger1 29-Nov-14 16:04pm    
thanks for answer just i don't know why i didn't think to change my code with this you said
;)
and i have one more question why it gave me error when i count items not subItems?
items count and subItems count are one, please explain me to understand
With Respect
BillWoodruff 29-Nov-14 17:53pm    
The SubItems Collection of a ListViewItem will contain as many SubItems as you create and add to it: so, it's up to your code if every SubItem Collection has the same number of SubItems ... or not.

The other thing you need to be aware of is that the first Item in the SubItems Collection is always the Item the SubItems are being added to (whether you think of the ListViewItem that contains SubItems as a "parent," or just, usually, the first column entry: up to you).

Why the ListViewItem/SubItem structure was implemented this way: ask Microsoft :)

So, if you want to enumerate and clear only the SubItems, then your inner 'for loop should be: for(int i = 1; i < item.SubItems.Count; i++)
Avenger1 30-Nov-14 8:37am    
thanks
;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900