Jump to content

[RESOLVIDO][vb.net] Colorir linhas de uma datagrid


esquima

Recommended Posts

A datagridview é tem mais funcionalidades que a datagrid.

http://www.syncfusion.com/FAQ/winforms/FAQ_c44c.aspx#q745q

ve faq 5.14 How do I color a individual cell depending upon its value or some external method?

"The Dark Side Clouds Everthing. Impossible To See The Future Is."My rig: Intel Core 2 Quad Q9450 | abit IP35P | 4G Kingston 800 Mhz | XFX GeForce 9800 GX2 1G ddr3 | 2X WD5000AAJS 500Gb Sata 2 | PSU 600W || Caixa El-Diablo | Creative XMod

Link to comment
Share on other sites

Public Class DataGridColoredTextBoxColumn
     Inherits DataGridTextBoxColumn

     Public Sub New()
     End Sub

     Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

     ' the idea is to conditionally set the foreBrush and/or backbrush
     ' depending upon some crireria on the cell value
     ' Here, we color anything that begins with a letter higher than 'F'
     Try
          Dim o As Object
          o = Me.GetColumnValueAtRow(source, rowNum)
          If (Not (o) Is Nothing) Then
               Dim c As Char
               c = CType(o, String).Substring(0, 1)
               If (c > "F") Then
                     ' could be as simple as
                    ' backBrush = new SolidBrush(Color.Pink);
                    ' or something fancier...
                    backBrush = New LinearGradientBrush(bounds, Color.FromArgb(255, 200, 200), Color.FromArgb(128, 20, 20), LinearGradientMode.BackwardDiagonal)
                    foreBrush = New SolidBrush(Color.White)
               End If
          End If
          Catch ex As Exception
               ' empty catch
          Finally
               ' make sure the base class gets called to do the drawing with
                ' the possibly changed brushes
               MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)
          End Try

     End Sub
End Class 

"The Dark Side Clouds Everthing. Impossible To See The Future Is."My rig: Intel Core 2 Quad Q9450 | abit IP35P | 4G Kingston 800 Mhz | XFX GeForce 9800 GX2 1G ddr3 | 2X WD5000AAJS 500Gb Sata 2 | PSU 600W || Caixa El-Diablo | Creative XMod

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.