Forum Discussion

adam_finley's avatar
12 years ago

SftTreeControl32OCX - Can't Click on Cells or Items

I am trying to work with a SftTreeControl32OCX in a window in my company's custom applications.  It simply stores a list of about 188 items/cells that can be clicked on added/deleted from an adjacent SftTreeControl32OCX (which is defaulted to have 0 items/cells).



When I object spy the SftTreeControl32OCX (with the 188 items/cells), I can see a ListCount of 188.  In the window (which is fixed and cannot be resized) that the SftTreeControl32OCX resides, only the first 9 items/cells are visible onscreen (the rest are viewable by using the scroll bar).  The ChildCount of the SftTreeControl32OCX shows a count of 9, linking it to the number of viewable items/cells on screen (identified as TextObjects).



I have no problem clicking the TextObjects using the TextObject("").Click method.  However, I cannot use this same approach for any of the off screen items/cells.  I can use the List(0,0) method to return the text of any item/cell (on or offscreen) but this only returns the text.  I need to return the actual item/cell itself, so that I can use the .Click method on it.







1 Reply

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Adam,

     

    As far as I understand, you are using the Text Recognition technology to work with your control. There is another way - accessing native properties and methods of the control. See the example below. It was created for the SftTree control version 6.5, however, I suppose that you can use a similar approach.
     
    ' The script works with the "<Softelvdm>\SftTree OCX 6.5\Samples\VB6\CellEditing\" sample
    
    Sub Main
      Dim p, wMain, wTree, rowId, strCol, cellValue
    
      Set p = Sys.Process("Project1")
      Set wMain = p.VBObject("Form1")
      wMain.Activate
      Set wTree = wMain.VBObject("SftTree1")
    
      rowId = 1
      strCol = "First Column"
    
      cellValue = getCellValue(wTree, rowId, strCol)
      If VarType(cellValue) = 1 Then
        Log.Error "No value is returned."   
      Else
        Log.Message "The [" & rowId & ", '" & strCol & "'] cell's value is '" & cellValue & "'" 
      End If 
    
      cellValue = "<new value>"
      If setCellValue(wTree, rowId, strCol, cellValue) Then 
        Log.Message "The [" & rowId & ", '" & strCol & "'] cell's new value is '" & getCellValue(wTree, rowId, strCol) & "'" 
      End If
    
      If clickItem(wTree, rowId, strCol) Then
        Log.Message "The [" & rowId & ", '" & strCol & "'] cell was successfully clicked."
      End If
    End Sub
    
    Function getCellValue(wTree, rowId, strCol) Dim colId getCellValue = Null If Not checkRange(wTree, rowId, strCol) Then Exit Function End If colId = getColIdByName(wTree, rowId, strCol) getCellValue = wTree.Cell(rowId, colId).Text End Function
    Function setCellValue(wTree, rowId, strCol, cellValue) Dim colId setCellValue = False If Not checkRange(wTree, rowId, strCol) Then Exit Function End If colId = getColIdByName(wTree, rowId, strCol) wTree.Cell(rowId, colId).Text = cellValue setCellValue = True End Function
    Function clickItem(wTree, rowId, strCol) Dim colId, oCell, wEdit clickItem = False If Not checkRange(wTree, rowId, strCol) Then Exit Function End If colId = getColIdByName(wTree, rowId, strCol) Set oCell = wTree.Cell(rowId, colId) oCell.MakeVisible Call oCell.Edit(0, 0) Set wEdit = wTree.FindChild("Visible", True) Log.LockEvents(1) wEdit.Click Log.UnlockEvents Log.Event "The [" & rowId & ", '" & strCol & "'] cell was clicked." clickItem = True End Function
    Function checkRange(wTree, rowId, strCol) Dim rowCount, colId, colCount checkRange = False rowCount = wTree.ListCount If rowId < 0 Or rowId > rowCount - 1 Then Log.Error "Wrong row index." Exit Function End If If getColIdByName(wTree, rowId, strCol) = -1 Then Log.Error "Wrong column name." Exit Function End If checkRange = True End function
    Function getColIdByName(wTree, rowId, strCol) Dim colId, colText colcount = wTree.Columns For colId = 0 To colCount - 1 colText = wTree.ColumnText(colId) If SameText(colText, strCol) Then getColIdByName = colId Exit Function End If Next getColIdByName = -1 End Function
     
    BTW, in the following survey, you can vote for the target control to be supported in the future:
    http://support.smartbear.com/products/more-info/testcomplete-survey/