Category / Section
How to use a ColorEdit control in a cell and retrieve its value as a color object in WinForms GridControl?
1 min read
Setting ColorEdit control in a grid cell
To change a cell to ColorEdit cell, you can set the CellType to ColorEdit and the Text property to some appropriate color value. The color object can be retrieved from the ColorEdit cell by converting its type of the Text from string to Color by using the ConvertFromString() method of the TypeDescriptor.GetConverter().
C#
//set cell type gridControl1[2, 3].CellType = "ColorEdit"; //set initial value to Color.Aqua gridControl1[2, 3].Text = "Aqua"; //or to set a RGB color, use something like // gridControl1[4, 4].Text = "2, 12, 255"; //set initial value to RGB(2,12,255).... //to retrieve a Color object from this cell, use code such as Color c = (Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString(gridControl1[2,3].Text);
VB
'set cell type gridControl1(2, 3).CellType = "ColorEdit" 'set initial value to Color.Aqua gridControl1(2, 3).Text = "Aqua" 'or to set a RGB color, use something like ‘gridControl1[4, 4].Text = "2, 12, 255" 'set initial value to RGB(2,12,255)... 'to retrieve a Color object from this cell, use code such as Dim c As Color = CType(TypeDescriptor.GetConverter(GetType(Color)).ConvertFromString(gridControl1(4, 4).Text), Color)
The following screenshot illustrates the output.
Figure 1: CellType property set to ColorEdit
Samples:
C#: ColorEditCell
VB: ColorEditCell