SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    May 2000
    Location
    Auckland, New Zealand
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    How to check state of checkboxes in ttreeview?

    Hiya,

    I am out at a client doing some proof-of-concept scripts with Test Complete... pretty good results so far until today...

    One of the controls we want to automate is a TTreeView (the application is created in Borland Builder)... its the type of tree that has branches and nodes but also a checkbox next to each tree item. (Its a security settings screen, where various access rights are switched on/off).

    Code like this is fine for selecting the correct item in the tree:
    <font class="small">Code:</font><hr /><pre> Set w1 = Aliases.AdministratorProcess.TfmSecurityClass1.Win dow("TPageControl")
    Call w1.ClickTab("Functions")
    Set w2 = w1.Window("TTabSheet", "Functions").Window("TTreeView")
    Call w2.ClickItem("|Desktop/Console|Console|Run Console")
    Call w2.ClickItem("|Desktop/Console|Console|Run Console")
    </pre><hr />
    ...then I can simply used Sys.Keys(" ") to select the checkbox...

    However, we really want to know the state of the checkbox first (i.e. checked or unchecked) but cannot get any access to the checkbox object (the deepest I can get is the tree and from there use wItems etc).

    I have tried functions like
    <font class="small">Code:</font><hr /><pre>
    Set ourPicture = item.SelectedImage
    Log.Picture(ourPicture)
    </pre><hr />
    ...but without success.

    Any help greatly appreciated!

    Thanks guys.

    Johnny
    Attached Images Attached Images

  2. #2
    Junior Member
    Join Date
    May 2000
    Location
    Auckland, New Zealand
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to check state of checkboxes in ttreeview?

    By the way, my original post has an attached image showing the tree concerned.

  3. #3
    Senior Member
    Join Date
    Oct 2003
    Posts
    928
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to check state of checkboxes in ttreeview?

    Hi Johnny,

    You can use the following script routine to check whether an item is checked:
    <font class="small">Code:</font><hr /><pre>'VBScript
    Sub Main_Sample
    Dim wTreeView, ItemStr, IsChecked

    Set wTreeView = ...
    ItemStr = "&lt;item path&gt;"

    IsChecked = IsCheckedNode(wTreeView, ItemStr)
    If Not IsEmpty(IsChecked) Then
    If IsChecked Then
    Log.Message "The '" &amp; ItemStr &amp; "' tree node is checked."
    Else
    Log.Message "The '" &amp; ItemStr &amp; "' tree node isn't checked."
    End If
    End If
    End Sub

    Function IsCheckedNode(wTreeView, ItemStr)
    Dim TV_FIRST, TVM_GETITEMSTATE, TVIS_STATEIMAGEMASK, NodeHandle

    TV_FIRST = &amp;H1100
    TVM_GETITEMSTATE = TV_FIRST + 39
    TVIS_STATEIMAGEMASK = &amp;HF000
    checkBit = 8192

    NodeHandle = GetNodeHandle(wTreeView.wItems, ItemStr, 0)
    If IsEmpty(NodeHandle) Then
    Log.Error "Wrong item path."
    Exit Function
    End If
    IsCheckedNode = VarToBool(checkBit And Win32API.SendMessage(wTreeView.Handle, TVM_GETITEMSTATE, NodeHandle, TVIS_STATEIMAGEMASK))
    End Function

    Function GetNodeHandle(Items, ItemStr, Level)
    Dim ItemId, ItemCount, ItemArray, CurrentItem, TempResult

    ItemArray = Split(ItemStr, "|")
    ItemCount = Items.Count
    For ItemId = 0 To ItemCount - 1
    Set CurrentItem = Items.Item(ItemId)
    If SameText(CurrentItem.Text, ItemArray(Level)) Then
    TempResult = CurrentItem.Handle
    If Level &lt; UBound(ItemArray) Then
    TempResult = GetNodeHandle(CurrentItem.Items, ItemStr, Level + 1)
    End If
    End If
    Next
    GetNodeHandle = TempResult
    End Function</pre><hr />

    BTW, we have added a built-in way to check whether an item is checked in TestComplete 7. The beta version is available for TestComplete 6 users.
    Regards,
    Alex - SmartBear Support

  4. #4
    Junior Member
    Join Date
    May 2000
    Location
    Auckland, New Zealand
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to check state of checkboxes in ttreeview?

    Thanks Alex!

    I got this working...!
    Actually, not sure why, but it gave the inverse result.
    i.e. It said CHECKED when it wasn't and vice-versa... So it was completely useable!

    Thanks again.

    Johnny

  5. #5
    Member
    Join Date
    Jul 2008
    Posts
    146
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to check state of checkboxes in ttreeview?

    Hi Alex,
    Can we get a J script version of your script? I have the problem using TestComplete8.2.0. Unable to select the checkbox or get the state of the checkbox.Any help?

    Thanks

  6. #6
    Senior Member
    Join Date
    Oct 2003
    Posts
    928
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to check state of checkboxes in ttreeview?

    Hi,

    Here is the JScript version:

    <font class="small">Code:</font><hr /><pre>
    function Main_Sample()
    {
    var wTreeView, ItemStr, IsChecked;

    wTreeView = ...;
    ItemStr = "&lt;item path&gt;";

    IsChecked = IsCheckedNode(wTreeView, ItemStr);
    if (IsChecked != null)
    if (IsChecked)
    Log.Message("The '" + ItemStr + "' tree node is checked.");
    else
    Log.Message("The '" + ItemStr + "' tree node isn't checked.");

    }

    function IsCheckedNode(wTreeView, ItemStr)
    {
    var TV_FIRST, TVM_GETITEMSTATE, TVIS_STATEIMAGEMASK, NodeHandle;

    TV_FIRST = 0x1100;
    TVM_GETITEMSTATE = TV_FIRST + 39;
    TVIS_STATEIMAGEMASK = 0xF000;
    checkBit = 8192;

    NodeHandle = GetNodeHandle(wTreeView.wItems, ItemStr, 0);
    if (NodeHandle = null)
    {
    Log.Error("Wrong item path.");
    return;
    }
    return VarToBool(checkBit &amp; Win32API.SendMessage(wTreeView.Handle, TVM_GETITEMSTATE, NodeHandle, TVIS_STATEIMAGEMASK));
    }

    function GetNodeHandle(Items, ItemStr, Level)
    {
    var ItemId, ItemCount, ItemArray, CurrentItem, TempResult;
    ItemArray = ItemStr.split("|");
    ItemCount = Items.Count;
    for (ItemId = 0; ItemId &lt; ItemCount; ItemId++)
    {
    CurrentItem = Items.Item(ItemId);
    if (aqString.Compare(CurrentItem.Text, ItemArray(Level), false) == 0)
    {
    TempResult = CurrentItem.Handle;
    if (Level &lt; ItemArray.length - 1)
    TempResult = GetNodeHandle(CurrentItem.Items, ItemStr, Level + 1);
    }
    }
    return TempResult;
    }
    </pre><hr />

    BTW, the latest version of TestComplete is 8.50.
    Regards,
    Alex - SmartBear Support

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.34%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:30 AM.

Copyright BetaSoft Inc.