Experience in C++, C#, Java and Process : Living in Montreal

* What is my technical experience as a software developer

* What I have learned in the software business

* Where I am heading to in my career

* How to process in a project

Thursday, May 19, 2005

Change color of one cell in the DataGrid control ( C#)

http://datawebcontrols.com/faqs/CustomizingAppearance/ConditionalFormatting.shtml

The DataGrid provides a plethora of properties that can be set to specify the DataGrid's formatting. For example, you can have each consecutive row of a DataGrid alternate between two different colors merely by setting the DataGrid's AlternatingItemStyle's BackColor property.
While the AlternatingItemStyle is a great way to apply different formatting for every other DataGrid row, oftentimes developers want to perform conditional formatting based on the value(s) of a DataGrid row. For example, imagine a DataGrid that displays a list of products, including the product's name and price. Perhaps you want to draw the user's attention to products that are at "bargain-basement" prices. Namely, if a product has a price less than, say, $10.00, you want to have that row highlighted.
This can be accomplished by providing an event handler for the DataGrid's ItemDataBound event. The ItemDataBound fires once for each DataGridItem added to the DataGrid (that is, it fires once for each row that is added to the DataGrid). Essentially, what we need to do is in this event handler, check to see if the price is below the threshold ($10.00, or whatever lower bound you choose). If it is, then we want to set the DataGridItem's BackColor property to Yellow, thereby highlighting the row.

1 Comments:

  • At 3:07 AM , Anonymous Anonymous said...

    Hi!
    You may probably be very interested to know how one can manage to receive high yields on investments.
    There is no initial capital needed.
    You may commense earning with a sum that usually goes
    on daily food, that's 20-100 dollars.
    I have been participating in one company's work for several years,
    and I'm ready to share my secrets at my blog.

    Please visit my pages and send me private message to get the info.

    P.S. I make 1000-2000 per daily now.

    http://theinvestblog.com [url=http://theinvestblog.com]Online Investment Blog[/url]

     

Post a Comment

Subscribe to Post Comments [Atom]

<< Home