10404 : Adding time items, they all get the same color


Hi I have modified this code from one of the examples but i want to change the colour of some of the bars depending on the data Private Sub gantt1_OnNodeInserted(ByVal aGrid As PlexityHide.GTP.Grid, ByVal e As PlexityHide.GTP.NodeEventArgs) Handles gantt1.OnNodeInserted

            Dim row As Object = e.GridNode.ListItemWhenDataBound()
            Dim val As Object = e.GridNode.OwningCollection.NodeDataConnect.CurrencyManager.GetItemProperties().Find(“id”, True).GetValue(row)
            Dim val2 As String = e.GridNode.OwningCollection.NodeDataConnect.CurrencyManager.GetItemProperties().Find(“name”, True).GetValue(row)
            Dim view As String

            ‘ Set up tree using DataViews, in this sample we only allow for SubLevel zero (root nodes) to have sub nodes
            If e.GridNode.SubLevel = 0 Then
                Dim subNodeView As DataView = New DataView(dataSet21.project)
                If TypeOf val Is Int32 Then
                    subNodeView.RowFilter = “ownedby=” & val.ToString()
                    Select Case CStr(val2).Trim
                        Case “Shattered”
                            view = “sh”
                        Case Else
                            view = “ELSE”

                    End Select

                    subNodeView.RowFilter = “ownedby=-1”
                End If
                ‘ Set the SubNodes to bind to the subNodeView
                e.GridNode.SubNodes_DataSourceList = subNodeView
            End If

            ‘ Set up time items in layer 0 with a dataview of the time items dataset
            Dim gr As GanttRow = Gantt.GanttRowFromGridNode(e.GridNode)
            Dim timeitemView As DataView = New DataView(dataSet_timeitems1.timeitem)
            If TypeOf val Is Int32 Then
                timeitemView.RowFilter = “ownedby=” & val.ToString()

                timeitemView.RowFilter = “ownedby=-1”

            End If

            gr.Layers(0).NameInDS_Start = “start”
            gr.Layers(0).NameInDS_Stop = “stop”
            gr.Layers(0).DataSourceList = timeitemView

            If view = “ELSE” Then
                Dim ti1 As TimeItem = gr.Layers(0).AddNewTimeItem()
                ti1.TimeItemLayout.SelectHandles = Color.Black
                ti1.TimeItemLayout.BrushKind = BrushKind.GradientDiagonal
                ti1.TimeItemLayout.Color = Color.YellowGreen
                ti1.TimeItemLayout.GradientColor = Color.Yellow
                Dim ti2 As TimeItem = gr.Layers(0).AddNewTimeItem()
                ti2.TimeItemLayout.SelectHandles = Color.Black
                ti2.TimeItemLayout.BrushKind = BrushKind.GradientDiagonal
                ti2.TimeItemLayout.Color = Color.SteelBlue
                ti2.TimeItemLayout.GradientColor = Color.White
            End If



        End Sub

What do i need to change to do this

at the moment they still come out the one colour


Since the timeItemLayouts are objects that in this case is being re-used to for all time items you actually change the properties of that single TimeItemLayout over and over. You need to definie two different timeItemLayouts and use them distinctivly.

                TimeItemLayout til1=new TimeItemLayout()
                til1.SelectHandles = Color.Black
                til1.BrushKind = BrushKind.GradientDiagonal
                til1.Color = Color.YellowGreen
                til1.GradientColor = Color.Yellow

                TimeItemLayout til2=new TimeItemLayout()
                til2.SelectHandles = Color.Black
                til2.BrushKind = BrushKind.GradientDiagonal
                til2.Color = Color.SteelBlue
                til2.GradientColor = Color.White

Once you have that you go like this:

            If view = “ELSE” Then
                Dim ti1 As TimeItem = gr.Layers(0).AddNewTimeItem()
                Dim ti2 As TimeItem = gr.Layers(0).AddNewTimeItem()
           End If

Leave a Reply