Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGrid Row Colours

DataGrid Row Colours

Scheduled Pinned Locked Moved C#
questioncomdesignhostingtutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayess Tech
    wrote on last edited by
    #1

    Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au

    P M Z 3 Replies Last reply
    0
    • K Kayess Tech

      Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au

      P Offline
      P Offline
      Peter Molnar
      wrote on last edited by
      #2

      If you have a web form, override the ItemDataBound event. Peter Molnar

      K 1 Reply Last reply
      0
      • P Peter Molnar

        If you have a web form, override the ItemDataBound event. Peter Molnar

        K Offline
        K Offline
        Kayess Tech
        wrote on last edited by
        #3

        Hi, It is a Windows form control :) Web design and hosting http://www.kayess.com.au

        1 Reply Last reply
        0
        • K Kayess Tech

          Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          This shows you how to backgroud of each cell. I think there is another article in CP that helps you to change whole color of row: http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp[^] Mazy
          "One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji

          1 Reply Last reply
          0
          • K Kayess Tech

            Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au

            Z Offline
            Z Offline
            zaboboa
            wrote on last edited by
            #5

            In your form class after you added the grid to the form add: DataGridColoredRowColumn aTextColumn; for (int i = 1; i < numColumns; i++) { aTextColumn = new DataGridColoredRowBoxColumn ();} this.datagridStyle.GridColumnStyles.Add(aTextColumn); Add a new class DataGridColoredRowBoxColumn, in which you will override the paint method. public class DataGridColoredRowBoxColumn : DataGridTextBoxColumn { protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) { try { object o = this.GetColumnValueAtRow(source, rowNum); if( o!= null) { string str = (string)o; if (str == "WHATEVER YOU COMPARE TOO") { backBrush = new SolidBrush(Color.Pink); } } catch (Exception) {} finally { base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); } } }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups