By default, CrystalImageGridView allows you to display thumbnail images with a single border color (CellBorderColor property) that is displayed whenever the CrystalImageItem is selected. That's standard behavior, but a few months ago, I ran into a situation where I wanted to indicate a state for particular image items in the grid. At the time, the best way to handle was to give each CrystalImageItem a unique border color that could be displayed permanently, regardless of selection state. As a result, a range of items could have a red border, others could have a green border. You can create your own customized Collector object to assign these border colors. If you look at this example, I created a subclass from CrystalFileCollector and assigned border colors after all the Images were collected:
public class MyCollector : CrystalFileCollector { public override bool CollectImages() { bool result = base.CollectImages(); if (result) { int index = 0; foreach (CrystalImageItem imageItem in GridModel) { index++; if ((index % 2) == 0) { imageItem.BorderColor = Color.Red; } if ((index % 3) == 0) { imageItem.BorderColor = Color.Green; } } } return result; } }
That's kind of a cheesy example. You might want to examine the Tag property of CrystalImageItem, where you can store your own objects during the collection phase. However, for this simple example, it results in CrystalImageGridViewer displayed the following images with permanent border colors:
That looks fine, but what happens when the images are selected? There's a new property which determines the selected border color in this special mode. The selected border color gets drawn inside the state border color. This is so the user can see that the image item is selected, but also recognize the status of the item. Here's what it looks like when the selected border color is set to Black:
Achieving this in your own programs is easy. You will need to change a few properties in CrystalImageGridView in the Forms Designer within Visual Studio:
-
Set BorderSplitMode to True.
-
Set CellBorderColor to Transparent. (You will assign border colors programmatically through CrystalImageItem's BorderColor property.)
-
Set CellSplitColor to whatever you like for the inner selection border color.
-
Make sure BorderWidth is large enough. The inner and outer borders split this width, with the inner border taking up 1/3 of the size.
In the next release of the toolkit, I will have a sample program that demonstrates this feature.






Leave a comment