List Info

Thread: Trouble inserting into ListView




Trouble inserting into ListView
user name
2006-05-12 15:27:56
Your first approach is the one I use without problems.  e.g:
listView1.LargeImageList.Images.Add(image);
ListViewItem item = listView1.Items.Add(
    listView1.LargeImageList.Images.Count.ToString());
item.ImageIndex = listView1.LargeImageList.Images.Count - 1;

...where listView1.LargeImageList is manually assigned in
the Form Load
event handler.  I also tried with adding an ImageList in the
FormDesigner
and assigning that image list to the LargeImageList property
of the Form
in the designer.

I even tried disposing the image right after assigning the
index.  IIRC
some methods don't like that; but, that didn't cause any
problems.

The only other things I can think of that would be different
is the way
the ImageList is being created and how you Image object is
being created?

On Fri, 12 May 2006 07:52:45 -0700, Mont Rothstein
<mont.rothsteinGMAIL.COM> wrote:

>I've tried a couple of different approaches.
>
>Approach one uses indexes thus:
>ListView.LargeImageList.Images.Add(image);
>ListViewItem.ImageIndex =
ListView.LargeImageList.Images.Count - 1;
>
>Approach two is to use keys:
>ListView.LargeImageList.Images.Add(key, image);
>ListViewItem.ImageKey = key;
>
>Oh, one final approach I tried was two combine the two:
>ListView.LargeImageList.Images.Add(key, image);
>ListViewItem.ImageIndex =
ListView.LargeImageList.Images.IndexOfKey(key);
>
>I also tried to put something in the tag of the images
so I could go
through
>the image list and see if they were scrambled. 
Unfortunately ImageList
(or
>the ListView's use of ImageList) seems to copy the
image data and not the
>tag.
>
>Any ideas?
>
>Thanks,
>-Mont
>
>
>On 5/11/06, Peter Ritchie <
>dotnetwinforms.discuss.develop.competerritchie.com> wrote:
>>
>> How are you adding images to the image list, and
what index are you
using
>> for the ImageIndex property?
>>
>> On Thu, 11 May 2006 15:57:24 -0700, Mont Rothstein
>> <mont.rothsteinGMAIL.COM> wrote:
>>
>> >I am attempting to insert an item into a
ListView and I am experiencing
>> >difficulties.
>> >
>> >My ListView is set to Sort Ascending.  I add my
ListViewItem via the
>> >listView.Items.Add() method.
>> >
>> >The ListViewItem is added at the correct
position, the problem is with
>> the
>> >associated large image.
>> >
>> >I add an image to the LargeImageList for the
new ListViewItem.  I then
>> set
>> >the ImageIndex on the ListViewItem.
>> >
>> >My new item has the correct large image
(initially) but the item after
it
>> also has the new item's large image.  Then as I
click on any item after
>> the
>> >new one the large image on the selected item is
updated to have the
>> previous
>> >item's image.
>> >
>> >After clicking on the last item if I then click
on the new item it is
>> >updated to have the last item's large image.
>> >
>> >I've tried using both the ImageIndex and
ImageKey, with the same
result.
>> >
>> >I've even tried looping over all of the items,
looking up the index
from
>> the
>> >LargeImageList based on the Key and re-setting
it, no luck.
>> >
>> >Does anyone know what is going on here and what
I need to do for this
to
>> >work?
>>
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )