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. Formatting a single datagridview cell???

Formatting a single datagridview cell???

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 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.
  • P Offline
    P Offline
    printscreen12345
    wrote on last edited by
    #1

    Is it possible to format only a few datagridview cells? Please help, thanks!

    L 1 Reply Last reply
    0
    • P printscreen12345

      Is it possible to format only a few datagridview cells? Please help, thanks!

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      I'm not sure of the extent of formatting you plan on doing...but here is what I've done:

      	private void RowPrePaint( object sender, DataGridViewRowPrePaintEventArgs e )
      	{
      		if ( ( ( DataGridView )sender ).Name.StartsWith( "detail" ) )
      			return;
      		DataGridViewCell cell = viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "BatchSelectColumn" \];
                          bool ThisRowSelected = false;
                          if (cell.Value != null)
                          {
                              ThisRowSelected = cell.Value == DBNull.Value ? false : (bool)cell.Value;
                          }
      
      		ElementState rowState = states\[ new Guid(viewer.BatchGrid.Rows\[e.RowIndex\].Cells\["batchGuid"\].Value.ToString()) \];
      		if ( rowState.InvalidDate)
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dateReceived" \].Style.BackColor = Color.LightCoral;
      		else
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dateReceived" \].Style.BackColor =
      				ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info;
      		if ( rowState.OutOfSequence )
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "batchNumber" \].Style.BackColor = Color.LightCoral;
      		else
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "batchNumber" \].Style.BackColor =  
      				ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info;
      		if ( rowState.AmountOutOfBalance )
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dollarAmount" \].Style.BackColor = Color.LightCoral;
      		else
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "dollarAmount" \].Style.BackColor =
      				ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info;
      		if ( rowState.CountOutOfBalance )
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "formCount" \].Style.BackColor = Color.LightCoral;
      		else
      			viewer.BatchGrid.Rows\[ e.RowIndex \].Cells\[ "formCount" \].Style.BackColor =
      				ThisRowSelected ? Color.LightSteelBlue : SystemColors.Info;
      
      		if ( ThisRowSelected )
      			viewer.BatchGrid.Rows\[ e.RowIndex \].DefaultCellStyle.BackColor = Color.LightSteelBlue;
      		else
      			viewer.BatchGrid.Rows\[ e.RowIndex \].DefaultCellStyle.BackColor = SystemColors.Info;
      	}
      
      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