Home - Forums-.NET - FlyGrid.Net (Windows Forms) - ROW BackColor....is this possible?

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

ROW BackColor....is this possible?
Link Posted: 13-Dec-2005 08:58
I need SOME of my rows to have a white background color.  I need some of the rows to have a beige background color.

Two questions:  
1) Is this possible

and 2) If so, how?

Thanks in advance!

-LK
Link Posted: 13-Dec-2005 09:34
Here's a sample of what I'm trying to do:

Dim myNode As Node
For Each myNode In grdSiteList.Rows.Items
   Dim Valid As Boolean = CBool(myNode.Item("IsValid").ToString)
   If Not Valid Then
      myNode.BackColor = Color.Beige
   Else
      myNode.BackColor = Color.White
   End If
Next


Even if I had to step thru each column that would be fine:
      myNode.Item(0).BackColor = Color.Beige
      myNode.Item(1).BackColor = Color.Beige
      myNode.Item(2).BackColor = Color.Beige
      

But I can find no VB.Net samples that show whether or not this is even possible.

Thanks again in advance!
-LK
Link Posted: 13-Dec-2005 19:20
This example shows how to implement custom drawing on nodes to specify foreground and back colors on each node:
[VB]
Class CoolNode
  Inherits Node
  Implements IStyledNode

  Private _backColor As Color = Color.Empty

  Public Property BackColor() As Color
    Get
      Return _backColor
    End Get
    Set(ByVal Value As Color)
      If (Not _backColor.Equals(Value)) Then
        _backColor = Value
        Me.OnChange()
      End If
    End Set
  End Property

  Private _foreColor As Color = Color.Empty

  Public Property ForeColor() As Color
    Get
      Return _foreColor
    End Get
    Set(ByVal Value As Color)
      If (Not _foreColor.Equals(Value)) Then
        _foreColor = Value
        Me.OnChange()
      End If
    End Set
  End Property  

  Public Sub OnBeginPaint(ByVal info As NineRays.Windows.Forms.Grids.CellDrawInfo) Implements NineRays.Windows.Forms.Data.IStyledNode.OnBeginPaint
    If Not (info.cellSelected) Then
      info.customForeColor = _foreColor
      info.customBackColor = _backColor
      Return
    End If
  End Sub

  Public Sub OnEndPaint(ByVal info As NineRays.Windows.Forms.Grids.CellDrawInfo) Implements NineRays.Windows.Forms.Data.IStyledNode.OnEndPaint
    'clear custom colors
    info.customForeColor = Color.Empty
    info.customBackColor = Color.Empty
  End Sub
End Class
Link Posted: 16-Dec-2005 04:38
This was incredibly easy to implement.  Thanks 9Rays

-LK
Link Posted: 15-Mar-2006 05:16
How does one implement the CoolNode Class? I've been trying to iterate through the nodes of my virtual grid, casting each node as a CoolNode but I get a "Specified Cast is not valid" error...


            Dim CurrNode As CoolNode = New CoolNode
            For Each CurrNode In grid.Rows.Items
                If LCase(CurrNode.Item("FileLocationCol").ToString).IndexOf(".sldasm") > 0 Then
                    CurrNode.BackColor = Color.LightCyan
                End If
            Next


Not sure how to proceed. Thanks in advance for any help!
Link Posted: 15-Mar-2006 05:47
Did you add a CoolNode to your FlyGrid.Rows.Items?
Link Posted: 15-Mar-2006 05:54
I am using Virtual Mode, so i am not adding nodes individually. How can I override use of "normal" nodes and replace with CoolNode?
Link Posted: 15-Mar-2006 21:09
See the VirtualMode_InitNewNode event handler in the Virtual Grid sample. In this event handler in virtual mode you can create your own instances of nodes.
Do not forget that nodes created in this handler should be inherited from VirtualNode type.
Link Posted: 17-Mar-2006 05:01
Thanks for the pointers - I got it working!

For everyone else, here is the implementation to save you some time if you want to do the same:


Private Function GetNodeRow(ByVal node As NodeBase) As DataRowView
        Try
            Dim parent As NodeBase = node.Parent
            If (TypeOf parent Is VirtualRootNode) Then
                Dim drv() As DataRowView
                drv = selfRelatedDt.DefaultView.FindRows(New Object() {0, node.Index + 1})
                If drv.Length > 0 Then
                    'Added to style assembly nodes - EAP 3/16/2006
                    StyleNode(node, drv(0))
                    Return drv(0)
                End If
            Else
                Dim parentNodeRow As DataRowView = GetNodeRow(parent)
                If (Not parentNodeRow Is Nothing) Then
                    Dim parentId As Integer = CType(parentNodeRow("Id"), Integer)
                    Dim drv() As DataRowView
                    drv = selfRelatedDt.DefaultView.FindRows(New Object() {parentId, node.Index + 1})
                    If drv.Length > 0 Then
                        'Added to style assembly nodes - EAP 3/16/2006
                        StyleNode(node, drv(0))
                        Return drv(0)
                    End If
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function

    'Added to style nodes - EAP 3/16/2006
    Private Sub StyleNode(ByVal node As CoolNode, ByVal drv As DataRowView)
        If Not drv Is Nothing Then
            If drv.Item("PDMCheckout") = "No" Then
                node.BackColor = Color.LightGray
                node.ForeColor = Color.Black
            ElseIf drv.Item("IsSumNode") = "True" Then
                node.BackColor = Color.DodgerBlue
                node.ForeColor = Color.Navy
            ElseIf drv.Item("FileLocation").ToString.Substring(Len(drv.Item("FileLocation").ToString) - 3, 3).ToLower = "asm" Then
                node.BackColor = Color.Goldenrod
                node.ForeColor = Color.DarkGreen
            End If
        End If
    End Sub

    Private Function grid_VirtualMode_InitNewNode(ByVal sender As Object, ByVal parent As NodeBase, ByVal index As Integer) As NodeBase
        Dim StyledNode As CoolNode = New CoolNode(parent)
        Return StyledNode
    End Function

Class CoolNode
    Inherits VirtualNode
    Implements IStyledNode

    Private _backColor As Color = Color.Empty

    Public Sub New(ByVal parent As NineRays.Windows.Forms.Data.NodeBase)
        MyBase.New(parent)

    End Sub

    Public Property BackColor() As Color
        Get
            Return _backColor
        End Get
        Set(ByVal Value As Color)
            If (Not _backColor.Equals(Value)) Then
                _backColor = Value
                Me.OnChange()
            End If
        End Set
    End Property

    Private _foreColor As Color = Color.Empty

    Public Property ForeColor() As Color
        Get
            Return _foreColor
        End Get
        Set(ByVal Value As Color)
            If (Not _foreColor.Equals(Value)) Then
                _foreColor = Value
                Me.OnChange()
            End If
        End Set
    End Property

    Public Sub OnBeginPaint(ByVal info As NineRays.Windows.Forms.Grids.CellDrawInfo) Implements NineRays.Windows.Forms.Data.IStyledNode.OnBeginPaint
        If Not (info.cellSelected) Then
            info.customForeColor = _foreColor
            info.customBackColor = _backColor
            Return
        End If
    End Sub

    Public Sub OnEndPaint(ByVal info As NineRays.Windows.Forms.Grids.CellDrawInfo) Implements NineRays.Windows.Forms.Data.IStyledNode.OnEndPaint
        'clear custom colors
        info.customForeColor = Color.Empty
        info.customBackColor = Color.Empty
    End Sub
End Class
Link Posted: 18-Apr-2006 04:13
I have implemented the \"Cool Node\" class (see code in last posting of this thread) to create Styled Nodes that have conditional Backcolor. This works fine, but I am having trouble \"repainting\" the nodes when conditions change. Also, if I resort the data in the grid, the Backcolor of the sorted nodes changes but nodes further down the grid retain their original Backcolor.

I have tried using the PrepareGrid() method to try to repaint, but it doesn't work. I have also tried some of the methods described in other threads (flyGrid.Rows.RootNode = null;
flyGrid.Rows.Reset(); etc...) without success.

Any ideas?

Thanks,
Eric