Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I drag and drop an item in a listview if I don"t know which column the item will be in?

How can I drag and drop an item in a listview if I don"t know which column the item will be in?

The SilkTest help files have the following to say about identifying an object in a listview:-

Items in a listview can be identified by either of the following:

The simple name of the item in the first column
A string containing a semicolon that specifies the content of one or more columns

The following examples show how you can identify items within a listview:

This specification...   Identifies this item...
"x"                   An item "x" in the first column
"x;y;z"                   An item "x" in the first column, "y" in the second column, and "z" in the third column
"*;*;z"                 An item "z" in the third column
"x;y"                 An item "x" in the first column, and an item "y" in the second column
"x;*;z "                An item "x" in the first column, and "z" in the third column


We can take advantage of this to specify an item anywhere in any column without knowing its exact positioning. The following code snippet counts the number of columns on the desktop and then appends this as a suffix to the item to be dragged. This forces SilkTest to read every column until it finds the specified object to drag and then forces it to read every column again until it finds the drag destination.

//Window declarations
[-] window DialogBox ProgramManager
    [ ] tag "Program Manager"
    [-] ListView ListView1
        [ ] tag "$1"

//Drag and drop code
[-] testcase DragTest() appstate none
    [ ] integer iCols=0
    [ ] integer iItems=0
    [ ] string sSuffix=""
    [ ] 
    [ ] ProgramManager.SetActive ()
    [ ] window wDeskTop = ProgramManager.ListView1
    [ ] iCols = wDeskTop.GetColumnCount()
    [ ] sSuffix = Replicate(";*",iCols - 1)
    [ ] ProgramManager.ListView1.BeginDrag (1,""+sSuffix)
    [ ] ProgramManager.ListView1.EndDrag (""+sSuffix)

= the name of a object on your desktop you wish to drag.
= the name of a object on your desktop you wish to drag into.

Old KB# 20765

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:13
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.