views:

32

answers:

1

Hi All

When I click a button, I am trying to insert a new listview item.

It is supposed to go in a certain Group, and it will have an item, followed by two subitems. But my code isn't working.

ListViewItem lvi = new ListViewItem(itemtext, grouptext);

            lvi.SubItems.Add(subitem1);
            lvi.SubItems.Add(subitem2);
            lvi.ToolTipText = subitem1;
            items.Items.Add(lvi);

Can someone please help me out?

Thank you

+4  A: 

The overload of the ListViewItem constructor that you are using (string, string) is for the item text and the imageKey. You should be able to assign your item to the proper group by using the constructor overload that uses (string, ListViewGroup).

Something like this:

     ListViewGroup myGroup = items.Groups[0];
     ListViewItem lvi = new ListViewItem(itemtext, myGroup);
msergeant