> This may help you:
> when creating your datagrid columns, let them inherit from this class and not from the DataGridTextBoxcolumn.
> Now this code will go and check the data of the datagrid cell on the row selected and in my case on the column 1.
> You should chose the percentage column in your case.
>
> Then a check is going to be made on the value of the cell chosen: In my case i have 2 choices
> In your case you should make the switch on the percentage value entered in the cell.
> let the cases be of the type : 0 < value < 10 ..... 10 <= value < 20 ..........
>
> Automaticaly the colors of all the row cells will change to the color selected.
>
>
> I hope that this will help you. If you have any questions just mail me
[email protected]
>
>
>
> public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
> {
> TransDetail trans;
>
> public DataGridColoredTextBoxColumn(TransDetail TransTemp)
> {
> trans = TransTemp;
> }
>
> protected override void Paint(System.Drawing.Graphics g,
> System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
> source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush
> foreBrush, bool alignToRight)
> {
> // the idea is to conditionally set the foreBrush and/or backbrush
> // depending upon some crireria on the cell value
> try
> {
> if (rowNum != trans.dtgTrans.CurrentRowIndex)
> {
> DataGridCell cell = new DataGridCell(rowNum,1);
> // Saves the value of the cell into a string
> string c = trans.dtgTrans[cell].ToString();
>
> // Checks the value of that string with the 2 options
> switch(c)
> {
> case "Payment":
> {
> backBrush = new SolidBrush(Color.Beige);
> foreBrush = new SolidBrush(Color.Brown);
> break;
> }
> case "Bill":
> {
> backBrush = new SolidBrush(Color.LightGray);
> foreBrush = new SolidBrush(Color.Gray);
> break;
> }
> }
> }
> }
> catch
> {
> // Do nothing
> }
> finally
> {
> // make sure the base class gets called to do the drawing with
> // the possibly changed brushes
> base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
> }
> }
> }