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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

changing cell color

Thread ID:





48794 Sep 4,2006 10:48 PM UTC Sep 7,2006 04:18 PM UTC WinForms 4
Tags: GridControl
Charlie Mao
Asked On September 4, 2006 10:48 PM UTC

I was wondering if someone can help me out. When I add a row to my grid, I want to change not the entire row color, but just a particular cell in the row that was just added. I know this can be done in the PrepareViewStyleInfo, but is this the only way to do it. If not can someone please give me an example. thanks

Administrator [Syncfusion]
Replied On September 5, 2006 05:16 AM UTC

Hi Charlie,

Are you using DataBoundGrid? If so, you can do this by handling Model.QueryCellInfo or PrepareviewStyleInfo.

By default, DataBoundGrid doesn''''t store any style info properties. You can not set any cell or row specific properties for the DataBoundGrid other than the CellValue.You need to handle the PrepareViewStyleInfo (or Model.QueryCellInfo) Event to do this.Through this event you can set the style properties for the grid.

To set the BackColor for a cell, you check for the e.RowIndex/e.ColIndex, if that points to the row you desired, set the e.Style.BackColor for it.

See the KnowledgeBase Articles for more info.
QueryCellInfo event : http://www.syncfusion.com/Support/article.aspx?id=10351
PrepareViewStyleInfo event :http://www.syncfusion.com/Support/article.aspx?id=560

Please let me know if this helps.

Charlie Mao
Replied On September 5, 2006 05:16 PM UTC

Hey Haneef,
That worked, but when I add another row the previous cell color that I added goes away. What I''m trying to do is : I have two columns. If a row in one column is empty, then it highlights the other column. I''d like to do that for all my datagrids. So is there a way to put this in the form load or something to check for that? Please let me know if I am a bit confusing?


Administrator [Syncfusion]
Replied On September 6, 2006 04:47 AM UTC

Hi Charlie,

The PrepareviewStyleInfo event can be used to set the Style of cells in the Grid control. The following code snippet shows how to change the color of cell depends on the another cell content( condition is Text is empty).

private void PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
GridDataBoundGrid grid = sender as GridDataBoundGrid;

if( e.ColIndex == 2 && e.RowIndex > 0)
string s = grid.Model[e.RowIndex,e.ColIndex - 1].Text;
if( s == null || s == string.Empty)
e.Style.BackColor = Color.Red;

Here is a sample.

Best Regards,

Charlie Mao
Replied On September 7, 2006 04:18 PM UTC

Thanks Haneef,

It worked great!!! On another subject, I''m trying to learn how to build tabs with syncfusion, do you happen to have a sample project that has multiple tabs that look decent. Thanks for your help.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon