Update cell value and color

Hi,

I have a sfdatagrid with 2 columns.

Category and ColorCode with 2 different values and colors.

The color style is according to the color value in the sfdatagrid.

What I want to do is when I click the cell, the color picker will show up to allow me to choose the color I want.

After choosing the color, it should update the color cell value at the same time as the color style.


Attachment: PicturesColorCode_32a6fa45.rar

1 Reply

VS Vijayarasan Sivanandham Syncfusion Team January 3, 2022 10:57 AM UTC

Hi Mark Jayvee,

Your requirement can be achieved by creating the custom column in SfDataGrid. For more information, please refer the below knowledge base documentation link,

KB Link: https://www.syncfusion.com/kb/12730/how-to-add-the-colorpicker-column-in-winforms-datagrid-sfdatagrid

https://www.syncfusion.com/kb/11819/how-to-change-the-cell-background-based-on-the-cell-value-in-winforms-datagridsfdatagrid

The appearance of the record rows in SfDataGrid can be conditionally customized based on the content by handling the SfDataGrid.QueryRowStyle event. Please refer the below code snippet, 
private void OnQueryRowStyle(object sender, QueryRowStyleEventArgs e) 
{ 
            //apply conditional styling for the row data 
            if (e.RowType == RowType.DefaultRow) 
            { 
                //The following code shows how to apply conditional styling for the data table. 
                var userColourString = (e.RowData as DataRowView).Row["ColorCode"].ToString(); 
                e.Style.BackColor = ColorTranslator.FromHtml(userColourString); 
 
 
                //The following code shows how to apply conditional styling for Observable collection. 
                //var userColourString = (e.RowData as OrderInfo).ColorCode; 
                //e.Style.BackColor = ColorTranslator.FromHtml(userColourString); 
            } 
} 

Sample Link: https://www.syncfusion.com/downloads/support/forum/171615/ze/ColorColumn-35367081

For more information, please refer the below user guide documentation link,

UG Link: https://help.syncfusion.com/windowsforms/datagrid/conditionalstyling#styling-based-on-content-1

Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 


Loader.
Up arrow icon