Forum Discussion

John_Laird's avatar
John_Laird
Contributor
8 years ago

trouble accessing treeview item count property

So I have this Python code and I am trying to get the item count of a System.Windows.Forms.TreeView:

 

def miscdriver():
  editMultQueryDialog = Aliases.ACMConfig.FormCustomPropertyQuery
  if editMultQueryDialog.treeView1.Enabled is False:
    editMultQueryDialog.toolStrip1.ClickItem("Add")
  else:
    #deselect all nodes at root level
    tree = editMultQueryDialog.treeView1
    treeitems = tree.wItems #this is line 897
    treeitemcount = treeitems.Count
    for itemindex in range(0, treeitemcount):
      if editMultQueryDialog.treeView1.wItems.Item[itemindex].Checked is True:
        editMultQueryDialog.treeView1.wItems.Item[itemindex].Check(cbUnchecked)

TC12 consistently throws this error on the line 'tree.wItems':

 

AttributeError The object does not support this property or method. Error location: Unit: "ACM_EvalTests\ACM\Script\ConfigureObjectHelper" Line: 897 Column: 1.

AttributeError
The object does not support this property or method.
Error location:
Unit: "ACM_EvalTests\ACM\Script\ConfigureObjectHelper"
Line: 897 Column: 1.
 
If I go into Object Spy I can select the treeview and drill down into the item count property with no issue:
Aliases.ACMConfig.FormCustomPropertyQuery.WinFormsObject("treeView1").wItems.Count
 
Suggestions on resolving this?

2 Replies

  • OK so feeling stupid. Replacing treeView1 with WinFormsObject("treeView1") works. Why?

     

    def miscdriver():
      editMultQueryDialog = Aliases.ACMConfig.FormCustomPropertyQuery
      if editMultQueryDialog.treeView1.Enabled is False:
        editMultQueryDialog.toolStrip1.ClickItem("Add")
      else:
        #deselect all nodes at root level
        tree = editMultQueryDialog.WinFormsObject("treeView1")
        treeitems = tree.wItems
        treeitemcount = treeitems.Count
        for itemindex in range(0, treeitemcount):
          if editMultQueryDialog.WinFormsObject("treeView1").wItems.Item[itemindex].Checked is True:
            editMultQueryDialog.WinFormsObject("treeView1").wItems.Item[itemindex].Check(cbUnchecked)
    • Ryan_Moran's avatar
      Ryan_Moran
      Valued Contributor

      Short answer is: because the treeview control is not mapped.