File: TreeViewExample.class

package info (click to toggle)
gambas3 3.20.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 77,208 kB
  • sloc: ansic: 197,232; cpp: 124,273; sh: 18,999; javascript: 7,761; sql: 5,399; makefile: 2,358; perl: 1,397; xml: 490; python: 335
file content (184 lines) | stat: -rw-r--r-- 4,181 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
' Gambas class file

Public intEventNumber As Integer

Public Sub Form_Open()

  Dim picMale As Picture
  Dim picFemale As Picture

  picFemale = Picture["Female.png"]
  picMale = Picture["Male.png"]

  'This will populate our treeview with our starting entries
  'Note: I'll just keep the entries text and its key the same to keep it simple
  TreeView1.Add(("Bill"), ("Bill"), picMale)
  TreeView1.Add(("Ted"), ("Ted"), picMale, ("Bill"))
  TreeView1.Add(("Sally"), ("Sally"), picFemale, ("Bill"))
  TreeView1.Add(("Frank"), ("Frank"), picMale, ("Sally"))
  'TreeView1.MoveCurrent
  'TreeView1.Item.Selected = TRUE
  'TreeView1.Item.Expanded = TRUE

  TreeView1[("Bill")].Expanded = True

End

Private Sub RefreshInfo()

  'This little check just updates our label so that we know how many
  'children an entry has.

  Dim sText As String

  If Not TreeView1.Current Then
    Textlabel1.Text = ""
    Return
  Endif

  With TreeView1.Current

    If .Children > 1 Then
      sText = Subst(("&1 has &2 children."), .Text, .Children)
    Else If .Children = 0 Then
      sText = Subst(("&1 has no children."), .Text)
    Else
      sText = Subst(("&1 has 1 child."), .Text)
    End If

    sText &= "<br>" & ("Item rect is") & " (" & .X & "," & .Y & "," & .W & "," & .H & ")"

  End With

  TextLabel1.Text = sText

End

Public Sub TreeView1_Click()

  'This just updates our event stack
  AddLog(("Click"))

End

Public Sub Button1_Click()

  Dim sIcon As String
  Dim sParent As String

  If Textbox1.Text <> Null Then
    If RadioButton1.Value Then
      sIcon = "Male.png"
    Else
      sIcon = "Female.png"
    End If
    'Gets the parent item: the current item, or nothing is the treeview is void
    sParent = TreeView1.Key
    'Now we will add a new entry with a key and a name of what was in the text box
    'We will place it as a child of the currently selected entry
    TreeView1.Add(Textbox1.Text, Textbox1.Text, Picture[sIcon], sParent).EnsureVisible
    TreeView1.Item.EnsureVisible 'This will make sure that the item we just added to the list is in the visable area of the control. (Scrolling if necessary)
    TextBox1.Text = "" 'This empties out textbox
    RefreshInfo ' This will update our label and reflect the new number of kids
  End If

End

Public Sub Button2_Click()

  If Not TreeView1.Key Then Return
  'Lets remove the current cursor item
  TreeView1.Remove(TreeView1.Key)
  'Now move the cursor to the current item (since we are now pointing at a deleted item)
  'But first we check the count to make sure we didn't delete the last item in the list
  'if we did then we obviously don't run this part.
  If TreeView1.Count > 0 Then
    'TreeView1.MoveCurrent
    'This selects or 'highlights' our current item
    'TreeView1.Current.Selected = TRUE
    'This will update our label and reflect the new number of kids
    RefreshInfo
  End If

End

Public Sub TreeView1_Collapse()
  'This just updates our event stack

  AddLog(("Collapse"))

End

Public Sub TreeView1_DblClick()
  'This just updates our event stack

  AddLog(("DblClick"))

End

Public Sub TreeView1_Select()
  'This just updates our event stack

  RefreshInfo
  AddLog(("Select"))

End

Public Sub TreeView1_Delete()
  'This just updates our event stack

  AddLog(("Delete"))

End

Public Sub TreeView1_Expand()
  'This just updates our event stack

  AddLog(("Expand"))

End

Public Sub Button3_Click()

  TextArea1.Text = ""
  'IntEventNumber = 0

End

Public Sub About_Click()

  Message.Info(("TreeView example written by C. Packard and Fabien Hutrel."))

End

Public Sub TreeView1_Activate()
  'This just updates our event stack

  AddLog(("Activate"))

End

Public Sub TreeView1_Rename()
  'This just updates our event stack

  AddLog(("Rename"))

End

Private Sub AddLog(anevent As String)
  'This updates our event stack, this sub is used by all events... it display the current node key.

  Dim sKey As String

  Try sKey = TreeView1.Item.Key
  TextArea1.Text = ("Event") & "(" & intEventNumber & "): " & anevent & " " & ("Item:") & " '" & sKey & "'\n" & TextArea1.Text
  TextArea1.Pos = 0
  Inc intEventNumber

End

Public Sub TreeView1_Cancel()

  AddLog(("Cancel"))

End