10233 : Iterate all time items

Question

How do I get all the timeitems I have?
Something like gnt.TimeItemArea.Items does not exist.
And

For i = 0 To GNT_Plan.Grid.RootNodes.Count – 1
  For j = 0 To GNT_Plan.Grid.RootNodes(i).subnodes.count – 1
  Next
Next

gives me all nodes, but how do I get all timeitems?

When a special timeitem is clicked, I want all Timeitems belonging to this one (this are not only childs) to change their color or something. They are not linked and they are no childs in this case, just belonging to a special group.

So how can I parse through all timeitems on my Gantt?

Thanks a lot!

Answer

The code belows iterates all the nodes and all the time items in all layers on those nodes, to be complete the samples also iterates the time item texts and time item links…

 Private Sub buttonCompleteIteration_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonCompleteIteration.Click
   ‘ The root-level of the grid nodes you access this way;
   Dim i As Integer=0
   Do While i<gantt1.Grid.RootNodes.Count
  DoCompleteIterationForOneNode(gantt1.Grid.RootNodes(i))
    i += 1
   Loop
 End Sub

 Private Sub DoCompleteIterationForOneNode(ByVal gn As GridNode)
   ‘ Each gridnode has one cell per column
   Dim i As Integer=0
   Do While i<gn.GridStructure.Columns.Count
    Dim o As Object=gn.GetCell(i).Content.Value
    i += 1
   Loop

   ‘ Each gridnode that is part of a gantt-grid has a GanttRow
   Dim gr As GanttRow=GanttRow.FromGridNode(gn)

   ‘ Each GanttRow has layers, the normal scenario is that the GanttRow only has one layer
   i = 0
   Do While i<gr.Layers.Count
  ‘ Each Layer has time items
  Dim ii As Integer=0
  Do While ii<gr.Layers(i).Count
    ‘ Each Layer has time items
    Dim ti As PlexityHide.GTP.TimeItem=gr.Layers(i)(ii)

    ‘a Time item can have time item texts
    Dim iii As Integer=0
    Do While iii<ti.TimeItemTexts.Count
   ti.TimeItemTexts(iii).Text=””
     iii += 1
    Loop

    ‘ and a time item can also have links….       
    Dim links As ArrayList=gantt1.TimeItemLinks.GetLinksFromStart(ti)

    iii = 0
    Do While iii<links.Count
   Dim til As TimeItemLink=CType(IIf(TypeOf links(iii) Is TimeItemLink, links(iii), Nothing), TimeItemLink)
   ‘ Once you have a link you can access the seperate time items
   Dim ti1 As TimeItem=til.Target
   Dim ti2 As TimeItem=til.Start
     iii += 1
    Loop

   ii += 1
  Loop

    i += 1
   Loop

   ‘ A grid node may have sub-nodes….
   i = 0
   Do While i<gn.SubNodes.Count
     DoCompleteIterationForOneNode(gn.SubNodes(i))
    i += 1
   Loop

 End Sub

 

Leave a Reply