Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    DBGrid- Colorare una singola riga

    [OT]Figata La combo per scegliere il linguaggio[/OT]
    Ciao a tutti, è possibile colorare una singola riga di una DBGrid di un colore diverso dale altre righe? Ho guardato tra le proprietà, ma nn c'è un qualcosa del tipo dbgrid.rows(n).color
    Avete idee?
    -----
    101110101011101111100000
    -----

  2. #2
    codice:
    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
    Ho trovato questo. Ma nn so applicarlo, nel senso che questo viene usato alla creazione della riga, invece nel mio caso, la riga è già creata. Come posso fare?
    -----
    101110101011101111100000
    -----

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.