For a Windows Forms application we’re developing at work, we’re using the awesome suite of UI components from DevExpress, which among other things includes an Office 2007 style Ribbon. One thing I am sorely missing about the Ribbons API however, is extensibility. For example, for one Form I wanted to have a some kind of check box list inside a ribbon page group from which the user could select one or more items. The closest thing that the DevExpress Ribbon offers, is the Gallery control. However, it only allows you to create galleries that look like the ones in Office 2007 – for example the Style gallery…
…while what I really wanted, was something like this:
Not one to give up easily, I pushed and pulled at the Gallery control trying to find some way to customize it into what I wanted. In the end I came up with a work-around: Since each item in the gallery consists of a glyph (which is just an image) and a label, I could make the gallery look the way I wanted by rendering a custom Image that showed a checkbox (in either a checked or unchecked state) and text, and use these images as the glyphs for the items in the gallery. All I had to do then, was hook up an event handlers to the ItemClickEvent of the gallery, and swap out the glyph image of the clicked item with one containing either a checked or unchecked checkbox to simulate checking/unchecking an item. In the end, I ended up adding a bit more functionality (buttons for selecting/deselecting all items, grouping of selected items and a selection status icon) and wrapping it all up into a component that can be dropped onto a Form to convert any gallery into a checkbox list:
Its difficult to explain the functionality in words or using static images, so here’s a short video of the custom gallery in action:
I’m quite pleased with how this turned out – now lets just hope the customers like it too :)
Source Code and Demo Project
If you want to have a closer look, then you can download the source code and a demo project here (Note that unless you have DevExpress XtraBars Suite 7.3 or later installed you won’t be able to compile or run the project). It’s a bit rough around the edges still, but it functions perfectly (as you can see in the video!) :)