« C# Dynamic Sorting for Lazy Programmers | Main | Crystal Toolkit: Alpha Release 0.75 »

State colors with BorderSplitMode in CrystalImageGridView

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:

BorderSplitMode

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:

BorderSplitMode Selection Color

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:

BorderSplitMode Properties

  1. Set BorderSplitMode to True.

  2. Set CellBorderColor to Transparent. (You will assign border colors programmatically through CrystalImageItem's BorderColor property.)

  3. Set CellSplitColor to whatever you like for the inner selection border color.

  4. 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.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on April 18, 2007 1:11 AM.

The previous post in this blog was C# Dynamic Sorting for Lazy Programmers.

The next post in this blog is Crystal Toolkit: Alpha Release 0.75.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by Movable Type 4.1
Hosted by LivingDot