Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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.
 
 <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
 

 
 lsvAnalysts.Items.Add("1");                
 lsvAnalysts.Items.Add("2");
Posted 7-Nov-12 23:48pm
Edited 8-Nov-12 1:16am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Member 9562996 at 8-Nov-12 5:31am
   
No I am not getting subitem property? This is my code
ListViewItem i = new ListViewItem();
i.Content = "one";
Member 9562996 at 8-Nov-12 6:16am
   
Pls check my updated question
mehdi.sabet at 8-Nov-12 6:42am
   
can you add this two item in listliew by this code?
lsvAnalysts.Items.Add("1");
lsvAnalysts.Items.Add("2");
Member 9562996 at 8-Nov-12 6:52am
   
yes it is added and i got the value through selecteditem
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

ListViewItem item = new ListViewItem();
item.Subitems.Add or if it is a collection you can get Item[index].Subitems.add
  Permalink  
Comments
Member 9562996 at 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)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100