Hi,
It seems that the display of my UltraListView is much slower when I include an image from an image list with each of my items. In my case, the time it takes to display the list is approx. 4 times longer when I include an image from the image list as compared to when each item uses the default image (or no image). Below is a code snippet:
// Create image list for UltraListView that has 5 images
myacqsList.ViewSettingsDetails.ImageList = new ImageList();
myAcqsList.ViewSettingsDetails.ImageList.Images.Add(new icon(...));
// Set default image and image size
myAcqsList.ItemSettings.DefaultImage = new icon(...).ToBitmap();
myAcqsList.ViewSettingsDetails.ImageList.ImageSize = new System.Drawing.Size(16,16);
myAcqsList.ViewSettingsDetails.ImageSize = new System.Drawing.Size(16,16);
// Add an item to the list
...
string name = ...;
DataTime data = ...;
string acqID = ...;
UltraListViewSubItem reportSubItem = new UltraListViewSubItem();
UltraListViewSubItems[] subItems = { new UltraListViewSubItem(acqID, null), new UltraListViewSubItem(date, null), reportSubItem };
UltraListViewItem = new UltraListViewItem(name, subItems);
item.Appearance.Image = imageIndex; // assign correct index from image list.
item.Appearance.ImageHAlign = Infragistics.Win.HAlign.Left;
item.Appearance.ImageVAlign = Infragistics.Win.VAlign.Middle;
myAcqsList.Items.Add(item);
If I comment out the assignment to the Image so that the default image is used, the display is much faster. Alternatively, if I assign -1 as the image index, as shown below, so that no image is displayed the display is also much faster.
item.Appearance.Image = -1;
I'm using version 8.2 of the Infragistics Windows DLLs, so they are a little old.
Any idea why including an image from the image list would cause the display of the list view to be so much slower? Any help is appreciated.
Thanks,
Rob
When you assign the image's ImageList index to the Appearance.Image, the value is boxed so converting it to an integer causes a (slight) performance hit.
Also, when we get that index, we use it to access an item from the ImageList's Images collection. The collection's indexer actually clones the image every time you use it, basically causing a copy of every image to be made every time the control paints. Not very efficient obviously...
The solution is very simple - instead of assigning the index to the Appearance.Image property, assign a reference to the image, like so:
Appearance.Image = ImagesList.Images[n];
This solves both problems - we no longer have to box an integer, and there is no need to clone the images either.
Brian,
Thanks!!! That solved my problem. I didn't realize that a clone of the image was being created with my original method.