reading ListView content

P

phil2phil

Hi,
I have an application that loads data into a ListView object, is there
anyway for me to loop through that list row by row, column by column.
Currently the user selects a name from a dropdown and the listview
refreshes with data on that person, I need to then write that data out
to a file, but i'm not sure how to loop through a ListView? I know
there is a .Columns.Count property to tell me the total columns, but
how to get the rows to properly loop?
Thanks.
 
L

Lars-Inge Tønnessen \(VJ# MVP\)

Loop through the rows with the foreach statement.
foreach (System.Windows.Forms.ListViewItem itemRow in this.listView1.Items)
{
Loop through the columns with a for loop.
for( int counter = 0; counter < itemRow.SubItems.Count; counter++ )
{
Do your processing.
string MyText = itemRow.SubItems[counter].Text;



the complete code: I have a ListView on mu form called "listView1".

foreach (System.Windows.Forms.ListViewItem itemRow in this.listView1.Items)
{
for( int counter = 0; counter < itemRow.SubItems.Count; counter++ )
{
string MyText = itemRow.SubItems[counter].Text;
// Do something with MyText.
}
}


Regrads,
Lars-Inge Tønnessen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top