Color DataGridView cell on exception


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Color DataGridView cell on exception

  1. #1
    Join Date
    Jan 2007
    Posts
    24

    Color DataGridView cell on exception

    Hi,
    I'm using VB.NET 2005, and would like to color a cell on a DataGridView if an exception has been invoked. I have the following code snippet:

    Code:
    ' ############ GET THE NEW 'FROM' DATE ############
    
    Try
       tblRow.Item("From") = Convert.ToDateTime(strNewFromDate)
    
    Catch ex As Exception
    
       ' Problem with this date field, so leave blank
    
       ' Add 1 to the number of warnings count
       intNumberOfWarnings += 1
    
       ' Colour the cell in error
    
    End Try
    Is there a clever bit of code I need to use that will allow me to color this particular cell?

  2. #2
    Join Date
    Jul 2004
    Posts
    366

    Smile Coloring a Cell

    This is just a starting point for you. You'll have to tweak it a bit to make it work for you.

    dgv.CurrentRow.DefaultCellStyle.BackColor = Color.BlanchedAlmond

    this will at least highlight the entire row. Play around with currentrow.currentcell, might be what your looking for. Hope this helps.



    jb

  3. #3
    Join Date
    Jan 2007
    Posts
    24

    Smile

    Thanks for the tip.
    I've collected the rows and cells "in error" in an array, and I've looped through the array with the following line:

    Code:
    Me.DataGridView1.Rows(arWarningRow(intArrayPosition)).Cells(arWarningCell(intArrayPosition)).style.BackColor = Color.Yellow
    Works well!

Similar Threads

  1. JTable Cell Renderers
    By freesoft_2000 in forum Java
    Replies: 3
    Last Post: 11-25-2006, 04:53 AM
  2. Replies: 1
    Last Post: 09-27-2005, 09:48 PM
  3. Exception Handling in Exception Handlers
    By David Williams in forum .NET
    Replies: 1
    Last Post: 05-28-2002, 02:19 PM
  4. cell color onclick
    By Mark Taylor in forum Architecture and Design
    Replies: 1
    Last Post: 10-25-2000, 07:21 PM
  5. cell color onclick
    By Mark Taylor in forum Web
    Replies: 0
    Last Post: 10-24-2000, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center