guyr
11-27-2007, 01:08 AM
I'm running 4.0.7. I've searched the forums and found several relevant posts, but they are all old and unresolved, so I figured I'd start another one. Our application has a list box, and I want to automatically select the first item in the list after it has been populated from a dataset. I've tried every approach I can think of: populating the list dynamically via script in the ondata event, and following the example in the Guide for using the onclones event and attaching an event to the last clone. All approaches produce a corrupted listbox.
Here is an example using the onclones approach:
<canvas bgcolor="white" width="1024" height="768" title="List selection bug demo">
<dataset name="ds_embedded_hub">
<resultset>
<hub>
<name>ATLM</name>
<city>Atlanta</city>
<abbr>Atl</abbr>
<x>270</x>
<y>260</y>
</hub>
<hub>
<name>CHIL</name>
<city>Chicago</city>
<abbr>Chi</abbr>
<x>265</x>
<y>225</y>
</hub>
<hub>
<name>DCAO</name>
<city>Washington</city>
<abbr>DC</abbr>
<x>295</x>
<y>245</y>
</hub>
<hub>
<name>DENF</name>
<city>Denver</city>
<abbr>Den</abbr>
<x>205</x>
<y>240</y>
</hub>
<hub>
<name>DFWB</name>
<city>Dallas</city>
<abbr>Dal</abbr>
<x>235</x>
<y>270</y>
</hub>
<hub>
<name>FRAI</name>
<city>Frankfurt</city>
<abbr>Fft</abbr>
<x>540</x>
<y>200</y>
</hub>
<hub>
<name>HKCA</name>
<city>Hong Kong</city>
<abbr>HK</abbr>
<x>850</x>
<y>300</y>
</hub>
<hub>
<name>LAXG</name>
<city>Los Angeles</city>
<abbr>LA</abbr>
<x>165</x>
<y>260</y>
</hub>
<hub>
<name>LONI</name>
<city>London</city>
<abbr>Lon</abbr>
<x>520</x>
<y>195</y>
</hub>
<hub>
<name>MIAS</name>
<city>Miami</city>
<abbr>Mia</abbr>
<x>280</x>
<y>290</y>
</hub>
<hub>
<name>NYCM</name>
<city>New York</city>
<abbr>NY</abbr>
<x>310</x>
<y>230</y>
</hub>
<hub>
<name>PARC</name>
<city>Paris</city>
<abbr>Par</abbr>
<x>520</x>
<y>210</y>
</hub>
<hub>
<name>PHLB</name>
<city>Philadelphia</city>
<abbr>Phi</abbr>
<x>303</x>
<y>235</y>
</hub>
<hub>
<name>SEAD</name>
<city>Seattle</city>
<abbr>Sea</abbr>
<x>160</x>
<y>220</y>
</hub>
<hub>
<name>SFOK</name>
<city>San Francisco</city>
<abbr>SF</abbr>
<x>160</x>
<y>240</y>
</hub>
<hub>
<name>SNGP</name>
<city>Singapore</city>
<abbr>Sin</abbr>
<x>810</x>
<y>365</y>
</hub>
<hub>
<name>SYDN</name>
<city>Sydney</city>
<abbr>Syd</abbr>
<x>950</x>
<y>465</y>
</hub>
<hub>
<name>TOKY</name>
<city>Tokyo</city>
<abbr>Tok</abbr>
<x>910</x>
<y>260</y>
</hub>
<hub>
<name>TORO</name>
<city>Toronto</city>
<abbr>Tor</abbr>
<x>290</x>
<y>215</y>
</hub>
</resultset>
</dataset>
<view name="cpe_selection_view" width="${parent.width}" height="${parent.height}" >
<simplelayout axis="x" spacing="50"/>
<text>Hub List</text>
<list name="cpe_hub" shownitems="5">
<textlistitem value="${this.text}">
<datapath xpath="ds_embedded_hub:/resultset/hub/name/text()" >
<handler name="onclones">
Debug.write("cpe_hub list onclones handler");
<!--
if (!this['doneDel'])
{
this.doneDel = new LzDelegate(this, 'openOH')
this.doneDel.register(clones[clones.length - 1], 'oninit')
}
-->
</handler>
<method name="openOH">
parent.select(this.getCloneNumber(0));
// parent.selectItemAt(0);
</method>
</datapath>
</textlistitem>
</list>
</view>
</canvas>
When you run this, immediately scroll down the list box and select an item that was not initially displayed. All is fine. You can continue to select items without issue.
Now uncomment the doneDel code and run again. The first item in the list should be selected. Again scroll the listbox down and select an item that was not initially displayed. When I do this, the list jumps back up towards the top, selecting a seemingly arbitrary item.
I've struggled with this for a week now, and unfortunately see no solution. I've seen a suggestion to add an indicator onto the dynamic dataset indicating the first item should be selected. I can try that.
Here is an example using the onclones approach:
<canvas bgcolor="white" width="1024" height="768" title="List selection bug demo">
<dataset name="ds_embedded_hub">
<resultset>
<hub>
<name>ATLM</name>
<city>Atlanta</city>
<abbr>Atl</abbr>
<x>270</x>
<y>260</y>
</hub>
<hub>
<name>CHIL</name>
<city>Chicago</city>
<abbr>Chi</abbr>
<x>265</x>
<y>225</y>
</hub>
<hub>
<name>DCAO</name>
<city>Washington</city>
<abbr>DC</abbr>
<x>295</x>
<y>245</y>
</hub>
<hub>
<name>DENF</name>
<city>Denver</city>
<abbr>Den</abbr>
<x>205</x>
<y>240</y>
</hub>
<hub>
<name>DFWB</name>
<city>Dallas</city>
<abbr>Dal</abbr>
<x>235</x>
<y>270</y>
</hub>
<hub>
<name>FRAI</name>
<city>Frankfurt</city>
<abbr>Fft</abbr>
<x>540</x>
<y>200</y>
</hub>
<hub>
<name>HKCA</name>
<city>Hong Kong</city>
<abbr>HK</abbr>
<x>850</x>
<y>300</y>
</hub>
<hub>
<name>LAXG</name>
<city>Los Angeles</city>
<abbr>LA</abbr>
<x>165</x>
<y>260</y>
</hub>
<hub>
<name>LONI</name>
<city>London</city>
<abbr>Lon</abbr>
<x>520</x>
<y>195</y>
</hub>
<hub>
<name>MIAS</name>
<city>Miami</city>
<abbr>Mia</abbr>
<x>280</x>
<y>290</y>
</hub>
<hub>
<name>NYCM</name>
<city>New York</city>
<abbr>NY</abbr>
<x>310</x>
<y>230</y>
</hub>
<hub>
<name>PARC</name>
<city>Paris</city>
<abbr>Par</abbr>
<x>520</x>
<y>210</y>
</hub>
<hub>
<name>PHLB</name>
<city>Philadelphia</city>
<abbr>Phi</abbr>
<x>303</x>
<y>235</y>
</hub>
<hub>
<name>SEAD</name>
<city>Seattle</city>
<abbr>Sea</abbr>
<x>160</x>
<y>220</y>
</hub>
<hub>
<name>SFOK</name>
<city>San Francisco</city>
<abbr>SF</abbr>
<x>160</x>
<y>240</y>
</hub>
<hub>
<name>SNGP</name>
<city>Singapore</city>
<abbr>Sin</abbr>
<x>810</x>
<y>365</y>
</hub>
<hub>
<name>SYDN</name>
<city>Sydney</city>
<abbr>Syd</abbr>
<x>950</x>
<y>465</y>
</hub>
<hub>
<name>TOKY</name>
<city>Tokyo</city>
<abbr>Tok</abbr>
<x>910</x>
<y>260</y>
</hub>
<hub>
<name>TORO</name>
<city>Toronto</city>
<abbr>Tor</abbr>
<x>290</x>
<y>215</y>
</hub>
</resultset>
</dataset>
<view name="cpe_selection_view" width="${parent.width}" height="${parent.height}" >
<simplelayout axis="x" spacing="50"/>
<text>Hub List</text>
<list name="cpe_hub" shownitems="5">
<textlistitem value="${this.text}">
<datapath xpath="ds_embedded_hub:/resultset/hub/name/text()" >
<handler name="onclones">
Debug.write("cpe_hub list onclones handler");
<!--
if (!this['doneDel'])
{
this.doneDel = new LzDelegate(this, 'openOH')
this.doneDel.register(clones[clones.length - 1], 'oninit')
}
-->
</handler>
<method name="openOH">
parent.select(this.getCloneNumber(0));
// parent.selectItemAt(0);
</method>
</datapath>
</textlistitem>
</list>
</view>
</canvas>
When you run this, immediately scroll down the list box and select an item that was not initially displayed. All is fine. You can continue to select items without issue.
Now uncomment the doneDel code and run again. The first item in the list should be selected. Again scroll the listbox down and select an item that was not initially displayed. When I do this, the list jumps back up towards the top, selecting a seemingly arbitrary item.
I've struggled with this for a week now, and unfortunately see no solution. I've seen a suggestion to add an indicator onto the dynamic dataset indicating the first item should be selected. I can try that.