reading ListView content

  • Thread starter Thread starter phil2phil
  • Start date Start date
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.
 
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
 
Back
Top