Building GraffitiTreeViewNode from database

I’m trying to populate a GraffitiTreeView and it’s nodes from an SqLite database and I’m having some trouble with the variables. This code throws an error: “winProject.popProject.SelectionChanged, line 46 Type mismatch error. Expected class GraffitiTreeViewNode, but got class GraffitiTreeViewNode”

I need to pull my node names from the database but obviously with Xojo not designed for dynamic variable names I can’t make each node name unique. That’s why I tried adding (0), (1), (2) to my variable but that doesn’t work. Am I wasting my time on this or is there a way to get around this? Maybe I’m just approaching it all wrong.

'Load the TreeView
Var projectNode as new GraffitiTreeViewNode(currentProject_Name)
projectNode.Expanded = true
projectNode.Tag = "project"
projectNode.Icon = currentProject_IconPicture

Var c As Integer = 0
Var childNode() As new GraffitiTreeViewNode("")
childNode.Expanded = true

query = "SELECT * FROM project WHERE project_id = '" + currentProject_ID.ToText + "' AND parent_id = 'project'"
result = db("SelectionQuery", "data").SelectSQL(query)
For Each row As DatabaseRow In result
  
  childNode(c).Text = row.Column("name").stringValue
  childNode(c).Tag = row.Column("id").stringValue
  
  trvProject.AddNode(projectNode,childNode(c))
  
  c = c + 1
  
Next
result.Close

I haven’t a clue how Graffiti Tree works. But surely you want

dim childNode As new GraffitiTreeViewNode("")

INSIDE of the for … each. And you don’t need an array. Just make a new node and add it to the existing nodes.

2 Likes

I figured it out after scratching my head for two hours. I guess I just needed to post it here to get it… The following does what I want:

'Load the TreeView
Var projectNode as new GraffitiTreeViewNode(currentProject_Name)
projectNode.Expanded = true
projectNode.Tag = “project”
projectNode.Icon = currentProject_IconPicture

query = “SELECT * FROM project_controls WHERE project_id = '” + currentProject_ID.ToText + “’ AND parent_id = ‘project’”
result = db(“SelectionQuery”, “data”).SelectSQL(query)
For Each row As DatabaseRow In result

trvProject.AddChildNode( projectNode, new GraffitiTreeViewNode( row.Column(“name”).stringValue, True, Nil, Nil, False, True ) )

Next
result.Close

1 Like