Long strings in grouped listview in smallicon mode causes render problems

Adding items to a group of a listview which displays items in smallicon mode causes problems when being rendered after hovering above listview items. Didnt happen to me without groups or in another display mode (largeicons...). Tested in Windows 10. If needed i could provide a screencast.


<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="left" textcol="none">
	<label>Listview group bug</label>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData)</instruction>
		<instruction>	var tab = clickData.func.sourcetab;</instruction>
		<instruction>	var cmd = clickData.func.command;</instruction>
		<instruction>	</instruction>
		<instruction>    var dlg = clickData.func.dlg;</instruction>
		<instruction>    dlg.detach = true;</instruction>
		<instruction>	dlg.template = &quot;dialog&quot;;</instruction>
		<instruction>    dlg.title = &quot;Sample&quot;;</instruction>
		<instruction>    dlg.create();</instruction>
		<instruction>	</instruction>
		<instruction>	var lv1 = dlg.Control(&quot;listview1&quot;);</instruction>
		<instruction>	</instruction>
		<instruction>	//this makes problems</instruction>
		<instruction>	lv1.AddGroup(&quot;A&quot;, 1, &quot;c&quot;);</instruction>
		<instruction>	lv1.AddGroup(&quot;B&quot;, 2, &quot;c&quot;);</instruction>
		<instruction>	lv1.EnableGroupView(true);</instruction>
		<instruction>	</instruction>
		<instruction>	for(var i= 0; i &lt; 100; i++)</instruction>
		<instruction>		//lv1.AddItem(String(&quot;Long string to make it happen &quot; + i), i, 1);</instruction>
		<instruction>		lv1.AddItem(String( i), i, 1);//short enough to not break it</instruction>
		<instruction>	</instruction>
		<instruction>	//this works fine</instruction>
		<instruction>	/*</instruction>
		<instruction>	for(var i= 0; i &lt; 100; i++)</instruction>
		<instruction>			lv1.AddItem(String(&quot;Long string to make it happen &quot; + i));</instruction>
		<instruction>	*/</instruction>
		<instruction />
		<instruction>    dlg.show();</instruction>
		<instruction>	var msg;</instruction>
		<instruction>	do</instruction>
		<instruction>	{</instruction>
		<instruction>		msg = dlg.GetMsg();</instruction>
		<instruction>	       if (!msg.result) </instruction>
		<instruction>			break;</instruction>
		<instruction>		Log(&quot;Msgloop: Event=&quot; + msg.event + &quot; Value=&quot; + String(msg.value) + &quot; Sender=&quot; + msg.control);</instruction>
		<instruction />
		<instruction>	}</instruction>
		<instruction>	while(msg);</instruction>
		<instruction />
		<instruction>function Log(msg, e)</instruction>
		<instruction>	DOpus.Output(String(msg), e || false);</instruction>
		<instruction>==SCRIPT RESOURCES</instruction>
		<instruction>	&lt;resource name=&quot;dialog&quot; type=&quot;dialog&quot;&gt;</instruction>
		<instruction>		&lt;dialog fontsize=&quot;8&quot; height=&quot;222&quot; lang=&quot;english&quot; width=&quot;360&quot;&gt;</instruction>
		<instruction>			&lt;control height=&quot;198&quot; name=&quot;listview1&quot; type=&quot;listview&quot; viewmode=&quot;smallicon&quot; width=&quot;330&quot; x=&quot;6&quot; y=&quot;6&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>

Congratulations, you seem to have found a bug in the Windows listview control :smiley:
(The control has lots of bugs but this is one we've never come across before).

I spent a bit of time playing around with this. The problem seems to occur if the width of column 0 hasn't been set (or, has been set to too low a value). (Even though there are no columns, in list mode and small icon mode the listview uses the width of column 0 as the item width).

In your example I was able to fix it by adding these two lines of code:

	lv1.columns.GetColumnAt(0).width = 318;

The width you need to set the column to seems to be based on the pixel length of the longest string plus about 6 DPI-scaled pixels. In the next update we'll add a function to do this calculation automatically, so the above lines could be replaced with:


Thanks, this worked for me as well (in the actual context I came across this bug). And thanks for the future fix.

Guess I have to be a little proud :sweat_smile:

1 Like

The update with the SetItemWidth method is now available.

1 Like