Multi-valued cells with Developer Express grid
Introduction
The solution
Download
Thanks
Sometimes it is necessary to have multiple values in a single grid cell. For example consider a calendar with each cell representing a work day. A work day is described with several values such as duration, person on duty and color. If this is the case it would be convenient to edit all those values within one multi-valued day cell as shown in the picture.
Here we will deal with Developer Express grid control (www.devexpress.com). Though it does not allow having multi-valued cells but it makes possible to unite columns in so called bands. We will use this feature to achieve the effect of multi-valued cells. So let us start with creating an advanced banded grid view with bands for each multi-valued column. In our example there will be a band for Monday, another one for Tuesday and so on.

A multi-valued cell is represented by three cells in a row within one band.

In order to make such cells distinguishable we need to draw borders for them. Unfortunately it is not possible with standard DevExpress grid options therefore we will use advanced drawing facilities provided by CustomDrawCell event.
Here is a code snippet that uses MultiValuedCellsManager class. This class draws borders between multi-valued cells by handling CustomDrawCell event.
advBandedGridView1.OptionsSelection.EnableAppearanceFocusedRow = false;
advBandedGridView1.OptionsView.ShowColumnHeaders = false;
new MultiValuedCellsManager(advBandedGridView1, new Pen(Color.LightGray),
new Pen(Color.DarkOrange));
As a result our grid looks as expected:

Download
The source code of MultiValuedCellsManager class and the example of using it can be found in the downloads section of my website. Or just click here for fast access.
To Anton Kolesnik who helped me implementing MultiValuedCellsManager class.
More Devexpress articles Back to homepage
|
|