Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have created a listview through xaml file and have added items to it. How to add subitems to that list view? I am not getting subitems property. Pls help me

This is my code for Listview creation.

HTML
<ListView Height="228" HorizontalAlignment="Left" Margin="284,79,0,0" Name="lsvAnalysts" VerticalAlignment="Top" Width="381" SelectionChanged="lsvAnalysts_SelectionChanged"/>



This is my code for adding items to it



C#
lsvAnalysts.Items.Add("1");
lsvAnalysts.Items.Add("2");
Posted
Updated 8-Nov-12 0:16am
v2

The MSDN links you'll want to read are http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.aspx[^]and http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.listviewsubitem.aspx[^].
You access the subitems of your list view item through the ListViewItem.SubItems property Most important thing to remember is that the first sub-item refers to the owner list view item so to access the actual sub-items you need to index starting at 1. This will return you a ListViewSubItem object and you can get it's text string by calling ListViewSubItem.Text.
 
Share this answer
 
Comments
Red Chocolate 8-Nov-12 5:31am    
No I am not getting subitem property? This is my code
ListViewItem i = new ListViewItem();
i.Content = "one";
Red Chocolate 8-Nov-12 6:16am    
Pls check my updated question
mhd.sbt 8-Nov-12 6:42am    
can you add this two item in listliew by this code?
lsvAnalysts.Items.Add("1");
lsvAnalysts.Items.Add("2");
Red Chocolate 8-Nov-12 6:52am    
yes it is added and i got the value through selecteditem
ListViewItem item = new ListViewItem();
item.Subitems.Add or if it is a collection you can get Item[index].Subitems.add
 
Share this answer
 
Comments
Red Chocolate 8-Nov-12 6:54am    
No i am not getting Subitems property iteself even i added items as you said above

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