매크로/모듈(Module)

TreeView Control(Ⅲ)

고추탄 2022. 10. 23. 07:51

참조 : https://www.homeandlearn.org/introduction_to_treeviews.html

A. TreeViw Control 추가

1. TreeView 추가 컨트롤

2. 도구상자 TreeView 컨트롤 추가

3. UserForm에 TreeView 컨트롤 추가

4. TreeView 컨트롤 속성 변경

SMALL

B. 트리뷰에 상위 노드를 추가하려면 구문은 다음과 같으며,

Dim node As node

Set node = TreeView.Nodes.Add ( [Relative], [Relationship], [Key], [Text], [Image], [SelectedImage] ) as Node

             = 트리뷰오브젝트.Nodes.Add ( 상대, 관계, 키, 텍스트, 이미지, 선택된이미지 )

 

1. 트리뷰 개체 지정.

2. 노드 개체의 하위 루틴 추가 ( 하위 루틴 추가 후 6개의 "상대, 관계, 키, 텍스트, 이미지, 선택된

   이미지" 인수를 지정 할 수 있다. )

3. 처음 두 인수(Relative, Relationship)는 상대적인 관계 임.

4. 상대 인수를 사용하는 경우, 추가하려는 각 상위 노드에 대한 관계 값을 지정해야 함.

5. 관계는 tvwFirst, tvwLast, tvwNext, tvwPrevious, tvwChild 5개 값 중 하나가 될 수 있음 

6. 하위(자식) 노드를 추가 할 때, tvwChild 마지막 요소 하나를 사용 할 수 있음.

 

C. 샘플

1. 트리뷰 개체 지정.

   Treeview1.Nodes.Add Key:="item 1", Text:="Parent 1"

2. 하위 루틴 추가 ( 하위 노드에는 고유한 키 및 텍스트 값이 필요 )

   Treeview1.Nodes.Add "item 1", tvwChild, "some unique key", "text value"

3. 시트내용

Africa Americas Asia Australasia Europe
Botswana Argentina China Australia Austria
Cameroon Brazil Hong Kong Fiji Belgium
Egypt Canada India New zealand Cyprus
Ghana Honduras Israel Smaoa Denmark
Kenya Mexico Japan   England
South Africa USA South Korea   France
Tanzania   Pakistan   Germany
    Qatar   Ireland
    Thailand   Italy

4. UserForm 초기화 프로시저 모듈

Private Sub UserForm_Initialize()

  Worksheets("sheet1").Activate
 
 '========================================
 '  PARENT NODES
 '========================================

  TreeView1.Nodes.Add Key:=Sheet1.Cells(1, 1).Value, Text:=Sheet1.Cells(1, 1).Value
  TreeView1.Nodes.Add Key:=Sheet1.Cells(1, 2).Value, Text:=Sheet1.Cells(1, 2).Value
  TreeView1.Nodes.Add Key:=Sheet1.Cells(1, 3).Value, Text:=Sheet1.Cells(1, 3).Value
  TreeView1.Nodes.Add Key:=Sheet1.Cells(1, 4).Value, Text:=Sheet1.Cells(1, 4).Value
  TreeView1.Nodes.Add Key:=Sheet1.Cells(1, 5).Value, Text:=Sheet1.Cells(1, 5).Value

 '========================================
 '  CHILD NODES
 '========================================


  Call FillchildNodes(1, "Africa")
  Call FillchildNodes(2, "Americas")
  Call FillchildNodes(3, "Asia")
  Call FillchildNodes(4, "Australasia")
  Call FillchildNodes(5, "Europe")

End Sub

Sub FillchildNodes(ByVal col As Integer, ByVal continent As String)

 '=======================================================
 '  GET THE LAST ROW WITH DATA IN IT FOR COLUMN col
 '=======================================================
 
  Dim LastRow As Long
  Dim counter As Integer
  Dim country As Range
       
  LastRow = Sheet1.Cells(Sheet1.Rows.Count, col).End(xlUp).Row
       
 '=======================================================
 '  LOOP ROUND AND ADD CHILD NODES
 '=======================================================
 
  counter = 1
  
  For Each country In Range(Cells(2, col), Cells(LastRow, col))
  
      TreeView1.Nodes.Add Sheet1.Cells(1, col).Value, tvwChild, continent + CStr(counter), country
       
      counter = counter + 1
  
  Next country

End Sub

 

5. UserForm Open

 

-----------------------------------------------------------------------------------------------

  Relative

  • 친척 (=relation)

       a close/distant relative

       가까운/먼 친척

  • 동족, 동류, 상대(上代): 조상의 代

       The ibex is a distant relative of the mountain goat.

       야생 염소는 산악 염소의 먼 동족이다.

 

  Relationship

  • (두 사람·집단·국가 사이의) 관계 (→love-hate relationship)

       The relationship between the police and the local community has improved.

       경찰과 지역 주민들과의 관계가 개선되었다.

  • (연인) 관계

       Their affair did not develop into a lasting relationship.

       그들의 정사는 지속적인 관계로 발전되지 않았다.

  • (두 가지 이상 사물 사이의) 관계[관련(성)]

       the relationship between mental and physical health

       정신적 건강과 육체적 건강 사이의 관계

LIST