Control.columns.Autosize()

Control.columns.AutoSize() seems to resize the columns to the width of the widest item for that column in the listview control. If that’s narrower than the column title the title is truncated rather than the column width resizing to suit the title.

Is this by design or a buglette?

Are you only seeing this with the last column, when the listview isn't wide enough to fit it in without scrolling? Or with all columns?

It seems to happen with the second or third column in a listview containing four or more cols. Not at pc atm to check and test.

Happens with a listview that has no need to horizontal scroll.

Seems OK here:

function OnClick(clickData) {
    var Dlg = DOpus.Dlg;
    Dlg.window = clickData.func.sourcetab;
    Dlg.template = "dialog1";
    Dlg.detach = true;
    Dlg.Show();
	var listview = Dlg.Control("listview1");
	listview.AddItem("Test 1");
	listview.GetItemByName("Test 1").subitems(0) = "Test Sub 1.1";
	listview.GetItemByName("Test 1").subitems(1) = "Test Sub 1.2";
	listview.AddItem("Test 2");
	listview.GetItemByName("Test 2").subitems(0) = "Test Sub 2.1";
	listview.GetItemByName("Test 2").subitems(1) = "Test Sub 2.2";
    while (true) {
        var Msg = Dlg.GetMsg();
        if (!Msg.result) break;
        DOpus.Output("Msg Event = " + Msg.event);
		if (Msg.event == "click" && Msg.control == "Autosize") {
			listview.columns.AutoSize();
		}
    }
    DOpus.Output("Return code = " + Dlg.result);
}
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>New Button</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var Dlg = DOpus.Dlg;</instruction>
		<instruction>    Dlg.window = clickData.func.sourcetab;</instruction>
		<instruction>    Dlg.template = &quot;dialog1&quot;;</instruction>
		<instruction>    Dlg.detach = true;</instruction>
		<instruction>    Dlg.Show();</instruction>
		<instruction>	var listview = Dlg.Control(&quot;listview1&quot;);</instruction>
		<instruction>	listview.AddItem(&quot;Test 1&quot;);</instruction>
		<instruction>	listview.GetItemByName(&quot;Test 1&quot;).subitems(0) = &quot;Test Sub 1.1&quot;;</instruction>
		<instruction>	listview.GetItemByName(&quot;Test 1&quot;).subitems(1) = &quot;Test Sub 1.2&quot;;</instruction>
		<instruction>	listview.AddItem(&quot;Test 2&quot;);</instruction>
		<instruction>	listview.GetItemByName(&quot;Test 2&quot;).subitems(0) = &quot;Test Sub 2.1&quot;;</instruction>
		<instruction>	listview.GetItemByName(&quot;Test 2&quot;).subitems(1) = &quot;Test Sub 2.2&quot;;</instruction>
		<instruction>    while (true) {</instruction>
		<instruction>        var Msg = Dlg.GetMsg();</instruction>
		<instruction>        if (!Msg.result) break;</instruction>
		<instruction>        DOpus.Output(&quot;Msg Event = &quot; + Msg.event);</instruction>
		<instruction>		if (Msg.event == &quot;click&quot; &amp;&amp; Msg.control == &quot;Autosize&quot;) {</instruction>
		<instruction>			listview.columns.AutoSize();</instruction>
		<instruction>		}</instruction>
		<instruction>    }</instruction>
		<instruction>    DOpus.Output(&quot;Return code = &quot; + Dlg.result);</instruction>
		<instruction>}</instruction>
		<instruction>==SCRIPT RESOURCES</instruction>
		<instruction>&lt;resources&gt;</instruction>
		<instruction>	&lt;resource name=&quot;dialog1&quot; type=&quot;dialog&quot;&gt;</instruction>
		<instruction>		&lt;dialog fontsize=&quot;8&quot; height=&quot;114&quot; lang=&quot;english&quot; resize=&quot;yes&quot; standard_buttons=&quot;cancel&quot; width=&quot;150&quot;&gt;</instruction>
		<instruction>			&lt;control height=&quot;84&quot; name=&quot;listview1&quot; resize=&quot;wh&quot; type=&quot;listview&quot; viewmode=&quot;details&quot; width=&quot;138&quot; x=&quot;6&quot; y=&quot;6&quot;&gt;</instruction>
		<instruction>				&lt;columns&gt;</instruction>
		<instruction>					&lt;item text=&quot;Long Column Name 1&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;Long Column Name 2&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;Long Column Name 3&quot; /&gt;</instruction>
		<instruction>				&lt;/columns&gt;</instruction>
		<instruction>			&lt;/control&gt;</instruction>
		<instruction>			&lt;control height=&quot;14&quot; name=&quot;Autosize&quot; resize=&quot;y&quot; title=&quot;Autosize&quot; type=&quot;button&quot; width=&quot;50&quot; x=&quot;6&quot; y=&quot;96&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>
		<instruction>&lt;/resources&gt;</instruction>
	</function>
</button>

I’ll do some more testing to see if I can narrow down what triggers it tomorrow.

You might be on to something with it being related to scrolling - you can see it has happened to the third column on the screenshot of the Log Reader in my bulk meta script.

I can reproduce the problem with your example button. The first video shows the third column has not autosized correctly when I resize the dialog. It's resized for the column items rather than the title.

Could it be related to the 125% DPI I have to use on this laptop?

In the next video, it shows the same problem with no resizing of the lister and no scrolling. It's the third column again.

If it only happens with the last column then I know what that is. The way that works has been improved for the next beta.

Thanks.

In the second video it happens with the third of five columns, not the last though.

I can't get it to happen for any other columns.

Is the 2nd video using listview.columns.AutoSize(); or is it sizing/autosizing individual columns?

If you make the column name a much wider string, does it get wider then, or is it always the same size?

The 2nd video is using listview.columns.AutoSize(); The only thing I really do different to your example button above is to use dlg.Create(), populate the columns, then dlg.Show(). Changing that to just using dlg.Show() prior to populating seems to have no effect.

Had another thought - I am using dlg.LoadPosition(); to recall a stored lister size/position which differs from the == script resources dimensions in the second video. This is done before the dlg.Create(); though.

Here's what I see when I give the column a wider string.

Thanks for trying that. I think I see what's wrong. The width is based on the header string, but it's off by a few pixels.

Some of the basic Windows font-rendering/measuring APIs have slightly different kerning these days (they used to all be consistent, then some clever person changed some of them but not others) and we must not be using the right one there.

1 Like

Nice one. Cheers.

Thanks for persisting.

Turns out it wasn't kerning after all, but a more subtle DPI thing.

Got it fixed now, for the next beta.

Thanks again for the examples and testing!

1 Like

Confirmed that it's working fine here now with the latest beta. Thanks very much.

1 Like