Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, im making a new project in C# altough

I have a ListView

I add lines like this:

ListViewItem item1 = new ListViewItem("1");
item1.SubItems.Add("2");
item1.SubItems.Add("3");
item1.SubItems.Add("4");
item1.SubItems.Add("5");
item1.SubItems.Add("6");
item1.SubItems.Add("7");
listView1.Items.AddRange(new ListViewItem[] { item1 });


But how do i read this back?

I want to read every subitem for example

MessageBox: Subitem1
MessageBox: Subitem2

Thankyou
Posted
Comments
VR Karthikeyan 8-Oct-15 4:59am    
Are you using WPF or WinForms?

It is always a good idea to check the documentation[^] first.
 
Share this answer
 
Comments
kylai12n 7-Oct-15 9:15am    
Did that, does not really lay out the answear to be honest.
Richard MacCutchan 7-Oct-15 10:59am    
It does if you make the effort to study the documentation.
kylai12n 7-Oct-15 11:11am    
I read all, and that didnt help i did manage to get this working.

item1.SubItems[1]

But thats only in the same void

I need like ListView.Item[1].SubItems[1]
Richard MacCutchan 7-Oct-15 11:21am    
I need like ListView.Item[1].SubItems[1]
You only have one Item in your control, so the index value of 1 is out of range.
kylai12n 7-Oct-15 11:14am    
Edit figured it out

listView1.Items[0].SubItems[1]
Just a guess,
foreach(var item in item1.SubItems)<br />
{<br />
    MessageBox.Show(item.Text);<br />
}


-KR
 
Share this answer
 
Comments
kylai12n 7-Oct-15 9:16am    
I'd like something like this in another void somthing like:

ListView.Items[1].SubItem[3]

But than actually working ;(
listView1.Items[0].SubItems[1]

Works.
 
Share this answer
 

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