views:

93

answers:

1

What I'm trying to do, is to store all groupnames, items and subitems from a listview into a string. Take a look at the following screenshot.

http://i.imagehost.org/0355/5_35.png

I'm kind of stuck though, with the loop. I'm pretty sure i can figure out how to actually store it in a variable though.

The following code will loop through all of the listview Items:

int countGroups = csslistview.Items.Count;
foreach (ListViewItem lvi in csslistview.Items){
    //code here
    countGroups++;
}

But i can't figure out how to loop through all of the Groups. I tried this, but it's not working:

int countGroups = csslistview.Groups.Count;
foreach (ListViewItem lvi in csslistview.Groups){
    //code here
    countGroups++;
}

I'm trying to echo it out as CSS, if you're wondering. The grouname is the id/class/tag, the item is the rule, and the subitem is the property.

So, any ideas?

A: 

If I understand correctly the following shoul hopefully tell you how to access the data you want:

foreach (ListViewGroup grp in csslistview.Groups)
{
    System.Diagnostics.Debug.WriteLine("Group: " + grp.Header);
    foreach (ListViewItem lvi in grp.Items)
    {
        System.Diagnostics.Debug.WriteLine("Item: " + lvi.Text + " SubItem: " + lvi.SubItems[0].Text);
    }
}

I'm not sure what the group count variable is for, but you can use:

csslistview.Groups.Count

or

csslistview.Items.Count

to get the counts of groups and items.

ho1
perfect! Yeah i'm not sure either, actually, i'm just confused by what i wrote before actually.
Nike