0

I tried to save rows in listview control in database but i am not able to loop through each row. My listview is multicolumn, it have 4 column. I tried for loop:

     for (int i = 0; i < listview.Items.Count; i++)
        {
            String abc = listview.Items[i].Subitem[i].Text;
            //other varables
        }

But it is not working and giving error. So what is the best way to iterate Listview items in WPF.

3
Contributors
2
Replies
28
Views
2 Years
Discussion Span
Last Post by SteveDotNet
0

well what I would do is this because there are so few columns

string abs=listview.Items[i].Subitem[0].ToString();
abs+=listview.Items[i].Subitem[1].ToString();
abs+=listview.Items[i].Subitem[2].ToString();
abs+=listview.Items[i].Subitem[3].ToString();

OR you can put in another for loop if you have more columns

for (int i = 0; i < listview.Items.Count; ++i)
    string abs="";
    for(int j=0;j<=3;++j){        {
        abs+=listview.Items[i].Subitem[j].ToString();
    }
    do something with abs
}

That will help you understand the row,column(i,j) iterations of a matrix...

What you do with the data is something else entirely, so string abs is just one big string of all the 4 columns together per row

Edited by gtcorwin: edited for clarity

0

Congratulations on using WPF.
As a WPF developer one does NOT iterate over the items in ANY control.
What you should be doing is iterating over the collection that constitutes the Items control's DataSource.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.