HomeProductsSupportDownloadsOnline StoreOnLine DocumentationLicensingAbout UsContact Us

Need technical support or assistance?

Click Here.

Please remember to read our guidelines first.

 

 

You will receive advance information about products and web updates as well as free software and source code that we will soon make available.

Subscribe Now

Once your subscription is activated you will receive instructions on how to leave the list.

 
     
Hundreds of free Visual Basic source code snippets, activeX controls, tutorials, tips, projects and articles covering VB.NET and VB6! Great code on topics like MAPI, winsock programming, COM, MTS, XML, graphics, threading, timers, networking, API's and more!
Welcome to the largest single directory of ASP.NET resources. This free directory links to examples, articles, and tutorials. A searchable code library allows you to find scripts. A daily newsletter keeps you up to date on the latest submissions.
Search the best developer Web sites and hundreds of developer newsgroups... updated every thirty minutes!

TN00009 - Creating Row grouping using the ASP.Net ActiveGantt Scheduler Component

Applies to:
  • ActiveGantt Scheduler Component for ASP.Net (Web Server Control - VB.Net)
Summary:

From version 2.5.7 onwards it is possible to simulate TreeView behaviour for Row objects, like in the following example:

Child Row objects can be expanded or collapsed:

On a new empty web form create an ActiveGantt control named ActiveGanttVBACtl1 and paste the following code



    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        If Me.IsPostBack = False Then
            mp_LoadControlData()
            ActiveGanttVBACtl1.Draw()
        Else
            Dim AGOld As AGVBA20.ActiveGanttVBACtl
            AGOld = Session("Gantt")
            ActiveGanttVBACtl1.RowHeight = 20
            ActiveGanttVBACtl1.RowHeadings.Add("")
            ActiveGanttVBACtl1.Rows = AGOld.Rows
            ActiveGanttVBACtl1.Calculate()
        End If
    End Sub

    Private Sub mp_LoadControlData()
        ActiveGanttVBACtl1.RowHeight = 20
        ActiveGanttVBACtl1.RowHeadings.Add("")
        ActiveGanttVBACtl1.Rows.Add("K010", "Row K010", True)
        ActiveGanttVBACtl1.Rows.Item("K010").Tag = "-"
        ActiveGanttVBACtl1.Rows.Add("K010010", "Row K010010", True)
        ActiveGanttVBACtl1.Rows.Item("K010010").Tag = "-"
        ActiveGanttVBACtl1.Rows.Add("K010010010", "Row K010010010", True)
        ActiveGanttVBACtl1.Rows.Add("K010020", "Row K010020", True)
        ActiveGanttVBACtl1.Rows.Add("K010030", "Row K010030", True)
        ActiveGanttVBACtl1.Rows.Item("K010030").Tag = "-"
        ActiveGanttVBACtl1.Rows.Add("K010030010", "Row K010030010", True)
        ActiveGanttVBACtl1.Rows.Add("K010030020", "Row K010030020", True)
        ActiveGanttVBACtl1.Rows.Add("K020", "Row K020", True)
        ActiveGanttVBACtl1.Rows.Item("K020").Tag = "-"
        ActiveGanttVBACtl1.Rows.Add("K020010", "Row K020010", True)
        ActiveGanttVBACtl1.Rows.Add("K020020", "Row K020020", True)
        ActiveGanttVBACtl1.Rows.Add("K020030", "Row K020030", True)
        ActiveGanttVBACtl1.Rows.Add("K030", "Row K030", True)
        ActiveGanttVBACtl1.Rows.Item("K030").Tag = "-"
        ActiveGanttVBACtl1.Rows.Add("K030010", "Row K030010", True)
        ActiveGanttVBACtl1.Rows.Add("K030020", "Row K030020", True)
        ActiveGanttVBACtl1.Rows.Add("K030030", "Row K030030", True)
        ActiveGanttVBACtl1.Rows.Add("K030040", "Row K030040", True)
        Session("Gantt") = ActiveGanttVBACtl1
    End Sub

    Private Function IsSibling(ByVal sMasterKey As String, ByVal sKey As String) _
    As Boolean
        Dim sSiblingID As String
        If sMasterKey.Length() = 4 Then
            sSiblingID = "K"
        Else
            sSiblingID = sMasterKey.Substring(0, sMasterKey.Length - 3)
        End If
        If (sMasterKey.Length() = sKey.Length()) Then
            If (sKey.Substring(0, sSiblingID.Length()) = sSiblingID) Then
                Return True
            Else
                Return False
            End If
        Else
            Return False
        End If
    End Function

    Private Function bHasChildren(ByVal Index As Integer) As Boolean
        Dim sMasterKey As String
        Dim sKey As String
        If Index >= ActiveGanttVBACtl1.Rows.Count Then
            Return False
            Exit Function
        End If
        sMasterKey = ActiveGanttVBACtl1.Rows.Item(Index).Key
        Index = Index + 1
        sKey = ActiveGanttVBACtl1.Rows.Item(Index).Key
        If sKey.Length < sMasterKey.Length Then
            Return False
            Exit Function
        End If
        If sKey.Substring(0, sMasterKey.Length) = sMasterKey Then
            Return True
            Exit Function
        End If
    End Function

    Private Function bIsChild(ByVal Key As String) As Boolean
        If Key.Length() = 4 Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Sub HideChildren(ByVal sKey As String)
        Dim i As Integer
        Dim sChildKey As String
        For i = 1 To ActiveGanttVBACtl1.Rows.Count
            sChildKey = ActiveGanttVBACtl1.Rows.Item(i).Key
            If sChildKey.Length > sKey.Length() Then
                If (sChildKey.Substring(0, sKey.Length()) = sKey) And _
                (sChildKey.Length() > sKey.Length()) Then
                    ActiveGanttVBACtl1.Rows.Item(i).Height = -1
                End If
            End If
        Next i
    End Sub

    Private Sub ShowChildren(ByVal sKey As String)
        Dim i As Integer
        Dim sChildKey As String
        For i = 1 To ActiveGanttVBACtl1.Rows.Count
            sChildKey = ActiveGanttVBACtl1.Rows.Item(i).Key
            If sChildKey.Length() > sKey.Length() Then
                If (sChildKey.Substring(0, sKey.Length()) = sKey) And _
                (sChildKey.Length() > sKey.Length()) Then
                    ActiveGanttVBACtl1.Rows.Item(i).Height = 20
                    If ActiveGanttVBACtl1.Rows.Item(i).Tag = "+" Then
                        ActiveGanttVBACtl1.Rows.Item(i).Tag = "-"
                    End If
                End If
            End If
        Next i
    End Sub

    Private Sub ActiveGanttVBACtl1_RowClick(ByVal Index As Integer, _
    ByVal Position As System.Drawing.Point) Handles ActiveGanttVBACtl1.RowClick
        Dim sTag As String
        If bHasChildren(Index) = True Then
            sTag = ActiveGanttVBACtl1.Rows.Item(Index).Tag
            If sTag = "+" Then
                ActiveGanttVBACtl1.Rows.Item(Index).Tag = "-"
                ShowChildren(ActiveGanttVBACtl1.Rows.Item(Index).Key)
            ElseIf sTag = "-" Then
                ActiveGanttVBACtl1.Rows.Item(Index).Tag = "+"
                HideChildren(ActiveGanttVBACtl1.Rows.Item(Index).Key)
            End If
            ActiveGanttVBACtl1.Draw()
        End If
    End Sub

    Private Sub ActiveGanttVBACtl1_RowDraw(ByRef CustomDraw As Boolean, _
    ByVal Index As Long, ByRef oGraphics As System.Drawing.Graphics) _
    Handles ActiveGanttVBACtl1.RowDraw
        If ActiveGanttVBACtl1.Rows.Item(Index).Height > -1 Then
            CustomDraw = True
            Dim oTextBrush As System.Drawing.Brush
            Dim sCaption As String
            Dim sKey As String
            Dim sTag As String
            Dim oTextFont As New System.Drawing.Font("Arial", 8)
            Dim lTextX As Single
            Dim lTextY As Single
            oTextBrush = New System.Drawing.SolidBrush(Color.Black)
            sCaption = ActiveGanttVBACtl1.Rows.Item(Index).Caption
            sKey = ActiveGanttVBACtl1.Rows.Item(Index).Key
            sTag = ActiveGanttVBACtl1.Rows.Item(Index).Tag
            lTextX = ActiveGanttVBACtl1.RowHeadings.Item(1).Left + (sKey.Length * 5)
            lTextY = ActiveGanttVBACtl1.Rows.Item(Index).Top + 1
            If bHasChildren(Index) = True Then
                If sTag = "+" Then
                    oGraphics.DrawRectangle(New System.Drawing.Pen(Color.Black), _
                    New System.Drawing.Rectangle(lTextX - 10, _
                    ActiveGanttVBACtl1.Rows.Item(Index).Top + 3, 8, 8))
                    oGraphics.DrawLine(New System.Drawing.Pen(Color.Black), _
                    lTextX - 8, ActiveGanttVBACtl1.Rows.Item(Index).Top + 7, _
                    lTextX - 4, ActiveGanttVBACtl1.Rows.Item(Index).Top + 7)
                    oGraphics.DrawLine(New System.Drawing.Pen(Color.Black), _
                    lTextX - 6, ActiveGanttVBACtl1.Rows.Item(Index).Top + 5, _
                    lTextX - 6, ActiveGanttVBACtl1.Rows.Item(Index).Top + 9)
                ElseIf sTag = "-" Then
                    oGraphics.DrawRectangle(New System.Drawing.Pen(Color.Black), _
                    New System.Drawing.Rectangle(lTextX - 10, _
                    ActiveGanttVBACtl1.Rows.Item(Index).Top + 3, 8, 8))
                    oGraphics.DrawLine(New System.Drawing.Pen(Color.Black), _
                    lTextX - 8, ActiveGanttVBACtl1.Rows.Item(Index).Top + 7, _
                    lTextX - 4, ActiveGanttVBACtl1.Rows.Item(Index).Top + 7)
                End If
            End If
            If bIsChild(sKey) = True And sTag = "" Then
                Dim y As Single
                Dim x1 As Single
                x1 = ActiveGanttVBACtl1.RowHeadings.Item(1).Left + (sKey.Length * 5)
                y = CSng(ActiveGanttVBACtl1.Rows.Item(Index).Top + _
                ((ActiveGanttVBACtl1.Rows.Item(Index).Bottom - _
                ActiveGanttVBACtl1.Rows.Item(Index).Top) / 2))
                Dim oPen As System.Drawing.Pen
                oPen = New System.Drawing.Pen(Color.Gray)
                oPen.DashStyle = Drawing.Drawing2D.DashStyle.Dot
                oGraphics.DrawLine(oPen, x1, y, x1 - 5, y)
            End If
            oGraphics.DrawString(sCaption, oTextFont, oTextBrush, lTextX, lTextY)
        Else
            CustomDraw = False
        End If
    End Sub

    Private Sub ActiveGanttVBACtl1_FixedColumnDraw(ByRef oGraphics As _
    System.Drawing.Graphics) Handles ActiveGanttVBACtl1.FixedColumnDraw
        Dim i As Integer
        Dim k As Integer
        Dim sMasterKey As String
        Dim sKey As String
        Dim lTextX As Single
        Dim lTop As Single
        Dim lBottom As Single
        For i = 1 To ActiveGanttVBACtl1.Rows.Count
            sMasterKey = ActiveGanttVBACtl1.Rows.Item(i).Key
            If bHasChildren(i) = True And ActiveGanttVBACtl1.Rows.Item(i).Height > -1 _
            And ActiveGanttVBACtl1.Rows.Item(i).Tag = "-" Then
                lTextX = ActiveGanttVBACtl1.RowHeadings.Item(1).Left + _
                ((sMasterKey.Length() + 3) * 5) - 6
                lTop = CSng(ActiveGanttVBACtl1.Rows.Item(i).Top + _
                ((ActiveGanttVBACtl1.Rows.Item(i).Bottom - _
                ActiveGanttVBACtl1.Rows.Item(i).Top) / 2)) + 5
                If bHasChildren(i + 1) = False Then
                    lBottom = CSng(ActiveGanttVBACtl1.Rows.Item(i + 1).Top + _
                    ((ActiveGanttVBACtl1.Rows.Item(i + 1).Bottom - _
                    ActiveGanttVBACtl1.Rows.Item(i + 1).Top) / 2))
                Else
                    lBottom = CSng(ActiveGanttVBACtl1.Rows.Item(i + 1).Top) + 4
                End If
                Dim oPen As System.Drawing.Pen
                oPen = New System.Drawing.Pen(Color.Gray)
                oPen.DashStyle = Drawing.Drawing2D.DashStyle.Dot
                oGraphics.DrawLine(oPen, lTextX, lTop, lTextX, lBottom)
            End If
            For k = i + 1 To ActiveGanttVBACtl1.Rows.Count
                sKey = ActiveGanttVBACtl1.Rows.Item(k).Key
                If IsSibling(sMasterKey, sKey) = True Then
                    If ActiveGanttVBACtl1.Rows.Item(i).Height > -1 And _
                    ActiveGanttVBACtl1.Rows.Item(k).Height > -1 Then
                        lTextX = ActiveGanttVBACtl1.RowHeadings.Item(1).Left + _
                        (sKey.Length * 5) - 6
                        If (ActiveGanttVBACtl1.Rows.Item(i).Tag = "") Then
                            lTop = CSng(ActiveGanttVBACtl1.Rows.Item(i).Top + _
                            ((ActiveGanttVBACtl1.Rows.Item(i).Bottom - _
                            ActiveGanttVBACtl1.Rows.Item(i).Top) / 2))
                        Else
                            lTop = CSng(ActiveGanttVBACtl1.Rows.Item(i).Top + _
                            ((ActiveGanttVBACtl1.Rows.Item(i).Bottom - _
                            ActiveGanttVBACtl1.Rows.Item(i).Top) / 2)) + 1
                        End If
                        If (ActiveGanttVBACtl1.Rows.Item(k).Tag = "") Then
                            lBottom = CSng(ActiveGanttVBACtl1.Rows.Item(k).Top + _
                            ((ActiveGanttVBACtl1.Rows.Item(k).Bottom - _
                            ActiveGanttVBACtl1.Rows.Item(k).Top) / 2))
                        Else
                            lBottom = CSng(ActiveGanttVBACtl1.Rows.Item(k).Top) + 2
                        End If
                        Dim oPen As System.Drawing.Pen
                        oPen = New System.Drawing.Pen(Color.Gray)
                        oPen.DashStyle = Drawing.Drawing2D.DashStyle.Dot
                        oGraphics.DrawLine(oPen, lTextX, lTop, lTextX, lBottom)
                    End If
                    Exit For
                End If
            Next k
        Next i
    End Sub

    Private Sub ActiveGanttVBACtl1_Click(ByVal sender As Object, _
    ByVal e As System.Web.UI.ImageClickEventArgs) Handles ActiveGanttVBACtl1.Click
        ActiveGanttVBACtl1.Draw()
    End Sub

This code uses the RowDraw and FixedColumnDraw events to custom paint the Treeview. With some additional coding it can be adapted to most situations.

Home | Products | Support | Downloads | OnLine Store

Online Documentation | Licensing | About Us | Contact Us

Privacy Terms of use Copyright (c)2002-2004 Source Code Store. All trademarks are property of their legal owner.