Take the 2-minute tour ×

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.ToolTipText = subitem1;

Can someone please help me out?

Thank you

share|improve this question
What do you mean by It's not working.? does it not add the item to ListView or it adds the item to ListView but does not add it to specific group? And I don't see any group assignment in your code! –  decyclone Jul 1 '10 at 14:28
grouptext is where i tell it what group to put it in. (the groups already exist). And no, it just adds the item to a NEW group called Default. –  anon271334 Jul 1 '10 at 14:32
add comment

1 Answer

up vote 3 down vote accepted

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);
share|improve this answer
add comment

Your Answer

