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. DataTable - DataGrid

DataTable - DataGrid

Scheduled Pinned Locked Moved C#
question
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.
  • M Offline
    M Offline
    moonboy
    wrote on last edited by
    #1

    Ok, i have a DataTable with some columns, and i have a DataGrid. The DataGrid DataSource is my DataTable. So, how i color some elements? I want to color all elements in the Table = "F" and "I" Thanks. :)

    J 1 Reply Last reply
    0
    • M moonboy

      Ok, i have a DataTable with some columns, and i have a DataGrid. The DataGrid DataSource is my DataTable. So, how i color some elements? I want to color all elements in the Table = "F" and "I" Thanks. :)

      J Offline
      J Offline
      Jay Shankar
      wrote on last edited by
      #2

      the following article in CP, will guide you in achieving the goal Changing the background color of cells in a DataGrid Please revert back whether you could achieve the functionality or not? Regards, Jay

      M 1 Reply Last reply
      0
      • J Jay Shankar

        the following article in CP, will guide you in achieving the goal Changing the background color of cells in a DataGrid Please revert back whether you could achieve the functionality or not? Regards, Jay

        M Offline
        M Offline
        Moon Boy
        wrote on last edited by
        #3

        I dont know, im not using Colum or table styles, just DataSource. I Want color a element on a cell. I have a DataTable with some columns, and call this table in DataSource.

        J H 2 Replies Last reply
        0
        • M Moon Boy

          I dont know, im not using Colum or table styles, just DataSource. I Want color a element on a cell. I have a DataTable with some columns, and call this table in DataSource.

          J Offline
          J Offline
          Jay Shankar
          wrote on last edited by
          #4

          1.To do this you first have to create class derived from DataGridTextBoxColumn or DataGridColumnStyle. You then have to override the Paint() method of these classes. Implement the Paint Method as below

          protected  override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
          {	
          	string val = (string) GetColumnValueAtRow(source, rowNum);	
          	if(val == "T")		
          		foreBrush = Brushes.Green;	
          	else if (val == "F")		
          		foreBrush = Brushes.Red;	
          
          	base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
          }
          

          2. You will have to use DataGridColumnStyle to achieve the functionality. 3. Read the article, I had given you in my previuos reply. also download and run the sample project of the article. This will help you a lot. Regards, Jay.

          1 Reply Last reply
          0
          • M Moon Boy

            I dont know, im not using Colum or table styles, just DataSource. I Want color a element on a cell. I have a DataTable with some columns, and call this table in DataSource.

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            You're need to. It's not hard - just see the DataGrid.TableStyles property in the .NET Framework SDK documentation. If you don't, you can't. The other reply is correct in what you must do.

            Microsoft MVP, Visual C# My Articles

            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