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. Image for the cookie policy date
close icon

changing cell color

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

4 Replies

AD Administrator Syncfusion Team 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.
Regards,
Haneef


CM Charlie Mao 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?

Thanks


AD Administrator Syncfusion Team 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.
http://www.syncfusion.com/Support/user/uploads/GDBGValid_edd9cc9a.zip

Best Regards,
Haneef.


CM Charlie Mao 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.


Loader.
Live Chat Icon For mobile
Up arrow icon