We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Changing BackColor of a Single Cell Based on Coordinates

Thread ID:

Created:

Updated:

Platform:

Replies:

121856 Feb 1,2016 10:21 AM Feb 3,2016 01:46 AM Windows Forms 7
loading
Tags: GridGroupingControl
Caleb Whitaker
Asked On February 1, 2016 10:21 AM

I am using a GridGroupingControl and need to highlight a single cell based on it's coordinate. Specifically based on its column name and a particular primary key value on the row but I can get the coords if only I could figure out how to alter the style of only one cell. I've tried doing this a few different ways with no avail.
Currently I'm looping through the Records and when I find the correct one I am using the gridGroupingControl1.TableModel.SetCellInfo method but it doesn't seem to work. I cannot find any method or value on the Record object itself that will do this.

Is this possible? Any ideas?
I've Googled and not found anything usefull for my case.





Caleb Whitaker
Replied On February 1, 2016 11:45 AM

Now I am attempting to use the gridGroupingControl1.Table.GetTableCellStyle method to retrieve the cells style and then change its BackColor. Also not working thus far, nothing is changing.

Caleb Whitaker
Replied On February 1, 2016 12:27 PM

Another update:
I just tried using the QueryCellStyleInfo event. Not only did it not work, it dramatically slowed down my form so that's a no go as well.  

Pavithra Kodiyarasan [Syncfusion]
Replied On February 2, 2016 06:40 AM

Hi Caleb,

Thank you for your interest in Syncfusion products.


How to access the cell from co-ordinates

Please Find the below code snippet to get the row index and column index using co-ordinates.

//To calculate Row and column index of specified point

this.gridControl1.PointToRowCol(new Point(100, 100),out a,out b);

Cell based formatting using QueryCellInfo

To dynamically set the style properties on a cell, the QueryCellStyleInfo event has to be handled. You can access the row of the cell and check whether it is a RecordRow or not. Assuming the datasource as a DataTable, the GridRecordRow.Record.GetData method returns the data as a DataRowView object. Then by using the DataRowView, you can access the data in the row and after checking the conditions, change the style of the row. Refer to the following code example.
C#

this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(this.gridGroupingControl1_QueryCellStyleInfo);

private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)

{

    //Disables the row when the value of Name in the same row is Row1.

    if (e.TableCellIdentity.RowIndex != -1)

    {

     GridRecordRow rec =  this.gridGroupingControl1.Table.DisplayElements[e.TableCellIdentity.RowIndex]as GridRecordRow;       

     if (rec != null)

        {

            // Applies format by checking the value ‘Row1’

            DataRowView dr = rec.GetData() as DataRowView;

            if (dr != null && dr["Name"].Equals("Row1"))

            {

                e.Style.Enabled = false;

                e.Style.BackColor = Color.Azure;

            }

        }

    }

}


Sample:

ConditionalRowStyle-C#

Conditional formatting

To conditionally set the style of a row in the GridGroupingControl, you can apply the row styles by using the Conditional Formatting function. You can refer to the following code example to apply Conditional Formatting to the records that have the cell value of Row1.

C#










// Event triggering from designer

//Creates FormatDescriptor

Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor gridConditionalFormatDescriptor3 = new Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor(); 


//Conditional Formatting applied through designer

gridConditionalFormatDescriptor3.Appearance.AnyRecordFieldCell.Interior = new Syncfusion.Drawing.BrushInfo(System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(191)))), ((int)(((byte)(52))))));


gridConditionalFormatDescriptor3.Appearance.AnyRecordFieldCell.TextColor = System.Drawing.Color.White;


gridConditionalFormatDescriptor3.Appearance.AnyRecordFieldCell.Enabled = false;


// Applies format by checking the value ‘Row1’

gridConditionalFormatDescriptor3.Expression = "[Name]  LIKE \'Row1\'";

gridConditionalFormatDescriptor3.Name = "ConditionalFormat 1";


//Adds conditional format descriptor to the GridGroupingControl TableDescriptor. this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(gridConditionalFormatDescriptor3);

Sample:
http://www.syncfusion.com/downloads/support/forum/121856/ze/CS446617931



Regards,
Pavithra K.



Caleb Whitaker
Replied On February 2, 2016 11:27 AM

The QueryCellStyleInfo Event worked for what I needed. Just added in a condition checking the column index so it only colored that single cell rather than the whole row.

Thanks!

Caleb Whitaker
Replied On February 2, 2016 01:55 PM

Actaully I have a follow up question.
The QueryCellStyleInfo Event happens so many times that even a little complexity lags the form...
I'm gonig to keep hacking to see if I can get it running efficiently.
But I cannot use the Conditional Formatting way to select a single cell rather than a row correct?

Caleb Whitaker
Replied On February 2, 2016 03:20 PM

Nevermind!
I've got it working ok now. Only a slight delay is all.

Solai A L [Syncfusion]
Replied On February 3, 2016 01:46 AM

Hi Caleb,

Thank you for your update. We are glad to know that your issue has been solved.

The QueryCellStyleInfo event is used to dynamically set the style properties on a cell of a grid. So, it gets triggered repeatedly. And this GridConditionalFormatDescriptor can be used for applying formatting only based on records.

Thanks,
AL.Solai.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;