Articles in this section

How to get the RGB value when a color is selected in the ColorEdit cell in WinForms GridControl?

GridControl with ColorEdit cell

You can obtain the selected color from the Renderer.ControlValue of the current cell in the CurrentCellCloseDropDown event handler in WinForms GridControl.

private void Form1_Load(object sender, EventArgs e)
{
    this.gridControl1.ColWidths[3] = 100;

    //Set cell type as ColorEdit cell
    this.gridControl1[3, 3].CellType = "ColorEdit";
    this.gridControl1[3, 3].CellValueType = typeof(Color);
    this.gridControl1[3, 3].CellValue = "Blue";
    this.gridControl1.CurrentCellCloseDropDown += gridControl1_CurrentCellCloseDropDown;
}

void gridControl1_CurrentCellCloseDropDown(object sender, PopupClosedEventArgs e)
{
      //Get Grid's CurrentCell
     GridCurrentCell cc = this.gridControl1.CurrentCell;
     if (cc.Renderer is GridDropDownColorUICellRenderer)
     {
         //Convert CurrentCell control value to Color
        Color c = (Color)cc.Renderer.ControlValue;
        Console.WriteLine(c);
        Console.WriteLine("R-Val:"+c.R);
        Console.WriteLine("G-Val:"+c.G);
        Console.WriteLine("B-Val:"+c.B);
     }
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    Me.gridControl1.ColWidths(3) = 100

    'Set cell type as ColorEdit cell
    Me.gridControl1(3, 3).CellType = "ColorEdit"
    Me.gridControl1(3, 3).CellValueType = GetType(Color)
    Me.gridControl1(3, 3).CellValue = "Blue"
    AddHandler Me.gridControl1.CurrentCellCloseDropDown, AddressOf      gridControl1_CurrentCellCloseDropDown
End Sub

Private Sub gridControl1_CurrentCellCloseDropDown(ByVal sender As Object, ByVal e As PopupClosedEventArgs)
     'Get Grid's CurrentCell
    Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
    If TypeOf cc.Renderer Is GridDropDownColorUICellRenderer Then
          'Convert CurrentCell control value to Color
         Dim c As Color = CType(cc.Renderer.ControlValue, Color)
         Console.WriteLine(c)
         Console.WriteLine("R-Val:" & c.R)
         Console.WriteLine("G-Val:" & c.G)
         Console.WriteLine("B-Val:" & c.B)
    End If
End Sub

The following screenshot displays the Grid control with a ColorEdit cell.

Grid control with coloredit cell


Figure
1: Grid Control with ColorEdit Cell


The following is the output screenshot.

Output screenshot


Figure
2: Output screenshot

Conclusion

I hope you enjoyed learning about How to get the RGB value when a color is selected in the ColorEdit cell in WinForms GridControl.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied