AllExperts > Visual Basic 
Search      
Visual Basic
Volunteer
Answers to thousands of questions
 Home · More Visual Basic Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About S.Aziz
Expertise
All questions related to vb6 only. Excuse me for vb.net.

Experience
12 years as a programmer.

Organizations
Print Media

Publications
Math Skill Test VB6 Game Source Code published at Planet-Source --------------------------------------------------------------- http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=72322&lngWId=1 Holy Quran Source Code published at Planet-Source ------------------------------------------------- http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=72343&txtForceRefresh=82020091635140766 Right to Left Treeview & Listview Source Code published at Planet-Source ------------------------------------------------------------------------ http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=72376&lngWId=1

Education/Credentials
Commerce Graduate ICWAI

Awards and Honors
Wizard certificate from experts-exchange.com ============================================= http://www.experts-exchange.com/M_1214708.html Level 4 certificate from Yahoo!Answers ======================================= http://answers.yahoo.com/my/my;_ylt=AkjObjoI7Cr1x01J9syQ5RZ17hR.;_ylv=3

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > 2 level depth inheritance

Visual Basic - 2 level depth inheritance


Expert: S.Aziz - 10/28/2009

Question
Good day Sir.  I just want to ask how to make a 2 level depth inheritance in VB6? Thank you for your time and God bless.  Best regards.

Sincerely,

Josef Alarka

Answer
vb6 is not 100% Object Oriented but vb.net is. hereunder is a example of using inheritence (Treeview control) in vb6.

Option Explicit

Private WithEvents mTV As MSComctlLib.TreeView

Private m_bRectangleSelect As Boolean
Private m_x1 As Long, m_x2 As Long
Private m_y1 As Long, m_y2 As Long
Private m_bSingleSelect As Boolean
Private m_bSelectAll As Boolean
Private m_iShift As Integer
Private m_LastNode As MSComctlLib.Node

Event NodesSelected()

Public Property Let SingleSelect(ByVal bValue As Boolean)
 m_bSingleSelect = bValue
End Property

Public Property Let SelectAll(ByVal bValue As Boolean)
 m_bSelectAll = bValue
End Property

Public Property Set TV(tvValue As MSComctlLib.TreeView)
 Set mTV = tvValue
End Property

Private Sub Class_Terminate()
 Set mTV = Nothing
End Sub

Private Sub mTV_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If m_bSingleSelect Then Exit Sub
     
 m_iShift = Shift
 
 m_bRectangleSelect = False
 m_x2 = -1
 
 If (Button = vbLeftButton) Then
   If Shift = vbNormal Then
     If mTV.HitTest(X, Y) Is Nothing Then
       m_bRectangleSelect = True
       m_x1 = X / Screen.TwipsPerPixelX
       m_y1 = Y / Screen.TwipsPerPixelY
       m_x2 = -9
       mTV.Tag = "rect"
     End If
   End If
 End If

End Sub

Private Sub mTV_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If m_bSingleSelect Then Exit Sub
 
 If Button = vbLeftButton And Shift = vbNormal Then
   If m_x2 = -9 Or m_bRectangleSelect Then
     If m_x2 <> -9 Then
       DrawRectOnHwnd mTV.hWnd, m_x1, m_y1, m_x2, m_y2
     End If
     m_bRectangleSelect = True
     m_x2 = X / Screen.TwipsPerPixelX
     m_y2 = Y / Screen.TwipsPerPixelY
     DrawRectOnHwnd mTV.hWnd, m_x1, m_y1, m_x2, m_y2
   End If
 End If
End Sub

Private Sub mTV_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If m_bSingleSelect Then Exit Sub
 
 If m_x2 >= 0 Then
   If Button = vbLeftButton And Shift = vbNormal Then
     If m_bRectangleSelect Then
       RectangleSelect mTV
       mTV.Refresh
     End If
   End If
 End If
 mTV.Tag = ""
 m_bRectangleSelect = False
 m_x2 = -1
End Sub

Private Sub RectangleSelect(myTV As MSComctlLib.TreeView)
 If Not m_bRectangleSelect Then Exit Sub
 
 TVRectangleSelect myTV, m_x1, m_x2, m_y1, m_y2, m_bSelectAll
 RaiseEvent NodesSelected
End Sub

Private Sub SelectShift()
 Dim curNode As MSComctlLib.Node
 Dim bOK As Boolean
 
 If mTV.Nodes.Count > 0 Then
   Set curNode = m_LastNode
   
   Do
     If Len(curNode.Tag) > 0 Then
       If curNode.Key = m_LastNode.Key Then bOK = True
       If bOK Then
         curNode.BackColor = vbHighlight
         curNode.ForeColor = vbHighlightText
       End If
       If curNode.Key = mTV.SelectedItem.Key Then bOK = False
     End If
     Set curNode = curNode.Next
   Loop Until curNode Is Nothing
 End If


End Sub

Private Sub mTV_NodeClick(ByVal Node As MSComctlLib.Node)
 Dim curNode As MSComctlLib.Node
   
 If Len(Node.Tag) = 0 Then Exit Sub
 
 Select Case m_iShift
   
   Case vbNormal
     Set m_LastNode = Node
     
     With mTV
       If .Nodes.Count > 0 Then
         For Each curNode In .Nodes
           curNode.BackColor = vbWindowBackground
           curNode.ForeColor = vbButtonText
         Next
       End If
     End With
   
   Case vbShiftMask
     If Not m_LastNode Is Nothing Then
       If Not mTV.SelectedItem Is Nothing Then
         SelectShift
       End If
     End If
     Set m_LastNode = Nothing
     
   Case vbCtrlMask
     Set m_LastNode = Nothing
     
 End Select
 
 Node.BackColor = vbHighlight
 Node.ForeColor = vbHighlightText
 
 m_iShift = 0
End Sub

*******In the desired form add a reference to the control********

Private WithEvents m_ctvFrom As clsTreeView

Private Sub Form_Load()
 Set m_ctvFrom = New clsTreeView
 Set m_ctvFrom.TV = tvFrom ' <- The real TreeView
End Sub

Private Sub Form_Unload(Cancel As Integer)
 Set m_ctvFrom.TV = Nothing
 Set m_ctvFrom = Nothing
End Sub


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.