Forum Discussion

ChrisA_1's avatar
ChrisA_1
Occasional Contributor
13 years ago

Wierd WPFListbox issues - can't get the wItem listings

I've just now hit a snag in my WPF Automation (Yes, the plug-in is installed and working).



I have a WPF Listbox that I am trying to select a specific item, but cannot guarantee that the item's index will always be the same.



Aliases.UTSEnterprise1.HwndSource_ApplicationWindow.ApplicationWindow.LayoutRoot.zWorkspaceGrid.zAppDock.LayoutRoot.zAppDock.BankDeposit.Grid.zLayoutRoot.zScrollViewer.zPageForm.zStackAllExpanders.zexpF1_Step3_CreatePrepareBankDeposit.zgrdLayout_Step3_F1.zstkStep3_F1.zgrd_F1_B.zstkDepositBags.zmultiselectDepositbags.zLayoutGrid.zSourceListBox.WPFObject("ListBoxItem", "", 1).WPFObject("Grid", "", 1).WPFObject("TextBlock", "Bag48474-1", 1).Name



This is the object I am looking for, and the caption/text is the "Bag48474-1"



I've looked at the Help and the Forums and nothing I try seems to get me to select the item in question.

I can select it via index and I can select all, but as I don't know what the index is if it's not the only item listed, I can't use that method to select it - the manual testers could have bags that they need for testing.



Here is the latest iteration of testing I have done to try and select the item.

Sub Test1

    Dim i, Item, Del, ItemString

    Dim msg

    Dim scrollViewer

    Dim listBox


    Set scrollViewer = Aliases.UTSEnterprise1.HwndSource_ApplicationWindow.ApplicationWindow.LayoutRoot.zWorkspaceGrid.zAppDock.LayoutRoot.zAppDock.BankDeposit.Grid.zLayoutRoot.zScrollViewer

    Set list = scrollViewer.zPageForm.zStackAllExpanders.zexpF1_Step3_CreatePrepareBankDeposit.zgrdLayout_Step3_F1.zstkStep3_F1.zgrd_F1_B.zstkDepositBags.zmultiselectDepositbags.zLayoutGrid.zSourceListBox


    ' Obtain the list of items and current delimiter

    ItemString = list.wItemList

    Del = list.wListSeparator

    aqString.ListSeparator = Del

    ' Extract particular items and post them to log

    For i = 0 To list.wItemCount - 1

        Item = aqString.GetListItem(ItemString, i)

        msg = MkSet(mbOK)

        msg = MessageDlg(Item, mtConfirmation, msg, 0)

    Next

End Sub

5 Replies

  • Hi,



    List box controls have the ClickItem and SelectItem methods which allow you to select their items by caption. You can find information on working with such controls in the Working With List Box Controls help topic.



    Do you face some problems if you try using these methods? If you do, what happens when you call them? Also, what happens if you try to access items via wItem instead of parsing the string returned from wItemList?
  • ChrisA_1's avatar
    ChrisA_1
    Occasional Contributor
    When I use ClickItem or SelectItem, nothing happens unless I use the index. And as stated, there is no way for me to KNOW what the index is as there may be other items in the listbox. So I need to select the item by caption/text.



    That's why - in the example code I gave above - I'm just trying to FIND the item in question.



    I'd do a ClickItem/SelectItem if it was working for me. The title is a misnomer. I tried wItem earlier andthat was on my brain when I entered the thread.
  • Hi,



    In this case, iterate through the items collection using you controls native properties as you'd do in your application. Look for something named Items, Nodes or similar. This will allow you to find the needed item's index.
  • ChrisA_1's avatar
    ChrisA_1
    Occasional Contributor
    I've been trying to do as you've suggested all day.

    Here is the critical code:



    '*************************************************************************************************************

    ' Actual Object Spy of the control down to the actual grid item in the listbox

    '*************************************************************************************************************

    'Aliases.UTSEnterprise1.HwndSource_ApplicationWindow.ApplicationWindow.LayoutRoot.zWorkspaceGrid.zAppDock

    '     .LayoutRoot.zAppDock.BankDeposit.Grid.zLayoutRoot.zScrollViewer.zPageForm.zStackAllExpanders

    '     .zexpF1_Step3_CreatePrepareBankDeposit.zgrdLayout_Step3_F1.zstkStep3_F1.zgrd_F1_B.zstkDepositBags

    '   
     .zmultiselectDepositbags.zLayoutGrid.zSourceListBox.WPFObject("ListBoxItem", "", 1)

    '     .WPFObject("Grid", "", 1).WPFObject("TextBlock", "Bag48474-1", 1)

    '*************************************************************************************************************


    Set scrollViewer = Aliases.UTSEnterprise1.HwndSource_ApplicationWindow.ApplicationWindow.LayoutRoot.zWorkspaceGrid.zAppDock.LayoutRoot.zAppDock.BankDeposit.Grid.zLayoutRoot.zScrollViewer


    Set list = scrollViewer.zPageForm.zStackAllExpanders.zexpF1_Step3_CreatePrepareBankDeposit.zgrdLayout_Step3_F1.zstkStep3_F1.zgrd_F1_B.zstkDepositBags.zmultiselectDepositbags.zLayoutGrid.zSourceListBox


    Set listItem = list.WPFObject("ListBoxItem", "", 1).WPFObject("Grid", "", 1)




    ' Obtain the list of items and current delimiter

    'NOTE - Nothing I put in here seems to help... I've read the help file on FindAll over and over.

    ItemString = listItem.FindAll("wndProps", "*", 5)



    ' Log the search results


    If UBound(ItemString) >= 0 Then

        For i = 0 To UBound(ItemString)

            msg = MessageDlg("FullName: " & ItemString(i), mtConfirmation, msg, 0)

       
    Next

    End If



    What do I need actually use in the FindAll statement to iterate through all the properties? Or is there a better/simpler way for getting the "Bag48474-1" Caption/Text?



    wItems returns 0

    The UBound(ItemString) returns -1

  • Hi,



    You don't need to use FindAll. Obtain the object with which you need to work and use its properties.

    listBox = ' Obtain your list box

    Set items = listBox.NativePropertyWhichReturnsTheNodeCollection



    For i = 0 To items.Count - 1 ' Count is an example

    ' code which works with items

    Next