{"id":843,"date":"2011-08-17T20:20:52","date_gmt":"2011-08-18T01:20:52","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=843"},"modified":"2021-03-10T20:40:38","modified_gmt":"2021-03-11T01:40:38","slug":"powerbuilder-selecting-and-scrolling-to-an-entry-in-a-listview-control","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-selecting-and-scrolling-to-an-entry-in-a-listview-control\/","title":{"rendered":"PowerBuilder &#8211; Selecting and scrolling to an entry in a Listview control"},"content":{"rendered":"<p>The listview control in PB lacks the capability to scroll to a highlighted item within the native Powerscript.  Here is an easy way to do this by simulating key strokes.  First declare the following API subroutine.<\/p>\n<pre name=\"code\" class=\"VB\">keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) Library &quot;user32.dll&quot;<\/pre>\n<p>Next create a user event in the listview control.  I called mine <strong>ue_scrolltoitem<\/strong>.  The event has two parameters, ai_oldindex and ai_newindex.  In this event put the following script.<\/p>\n<pre name=\"code\" class=\"VB\">listviewitem  lvi_1\nlong li_rc\n\/\/ unselect old value\nIF ai_oldindex &gt; 0 THEN\n\tli_rc = This.GetItem(ai_oldindex, lvi_1)\n\tlvi_1.HasFocus=FALSE\n\tlvi_1.selected=FALSE\n\tli_rc = This.SetItem(ai_oldindex , lvi_1)\nEND IF\n\/\/ select new value\nli_rc = This.GetItem(ai_newindex , lvi_1)\nlvi_1.HasFocus=TRUE\nlvi_1.selected=TRUE\nli_rc = This.SetItem(ai_newindex , lvi_1)\n\nthis.setfocus()\n\n\/\/ simulate up arrow then down arrow to move selected item into visible portion of the control\nIF ai_newindex &lt; this.totalitems( ) AND ai_newindex &gt; 1 THEN\n\t\/\/ decimal value of the virtural keyboard up arrow (0x26)\n\tkeybd_event( 38, 1, 0, 0)\n\t\/\/ decimal value of the virtural keyboard down arrow (0x28)\n\tkeybd_event(40,1,0,0)\nELSEIF ai_newindex = 1 THEN\n\t\/\/ decimal value of the virtural keyboard down arrow (0x28)\n\tkeybd_event(40,1,0,0)\n\t\/\/ decimal value of the virtural keyboard up arrow (0x26)\n\tkeybd_event( 38, 1, 0, 0)\nEND IF<\/pre>\n<p>This technique sets up the highlighted row as the last one in the visible portion of the control.  You can modify it to &#8216;scroll up&#8217; as many times as needed to put it at the top of the control should you need to do so.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The listview control in PB lacks the capability to scroll to a highlighted item within the native Powerscript. Here is an easy way to do this by simulating key strokes. First declare the following API subroutine. keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) Library &quot;user32.dll&quot; Next create a user event in the listview&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[12,16,42],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/843"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=843"}],"version-history":[{"count":6,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/843\/revisions"}],"predecessor-version":[{"id":1969,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/843\/revisions\/1969"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}