How to modify the width of the columns of a ListView?

Is it possible to change the width of a ListView's columns? I'm trying to change the values ​​to width, but it doesn't work. Thank you very much.

==SCRIPT RESOURCES
<resources>
	<resource name="dialog1" type="dialog">
		<dialog height="262" lang="esm" standard_buttons="ok,cancel" title="Renombrar" width="348">

         <!-- Panel vista previa -->
			<control header="yes" height="69" name="vista_previa" title="Vista previa" type="group" width="340" x="4" y="165" />
			<control enable="no" fullrow="yes" height="64" name="listview1" type="listview" viewmode="details" width="340" x="4" y="176">
				<columns>
					<item text="Nombre actual" width="100" />
					<item text="Extensión" width="30" />
					<item text="Nombre futuro" width="100" />
					<item text="Extensión" width="30" />
				</columns>
			</control>

Use the Control.SetItemWidth method.

Thanks for replying, but I tried the following, but the columns still don't change their widths.

dlg.Show();

dlg.Control("listview1").SetItemWidth(0, 100); // Nombre actual
dlg.Control("listview1").SetItemWidth(1, 30);  // Extensión
dlg.Control("listview1").SetItemWidth(2, 100); // Nombre futuro
dlg.Control("listview1").SetItemWidth(3, 30);  // Extensión
<control enable="no" fullrow="yes" height="64" name="listview1" type="listview" viewmode="details" width="340" x="4" y="176">
		<columns>
			<item text="Nombre actual" />
			<item text="Extensión" />
			<item text="Nombre futuro" />
			<item text="Extensión" />
		</columns>
</control>

Do you want to "autosize" the columns or set them to a specific width?

var lv =  dlg.Control("listview1");
var columns = lv.columns;
//to autosize all columns
columns.autosize();
//to set the column 0 to a desired width (20)
columns.GetColumnAt(0).width = 20;

More info:

1 Like

You'd normally resize the columns before showing the dialog.

If dlg.Show is modal (which depends on details we can't see from the code snippet) then the code as it is will be resizing the columns after the dialog has closed, which definitely isn't what you want.

Many thanks @Jon, @Leo and especially @errante, both methods worked very well, but I ended up choosing a fixed width:

var lv =  dlg.Control("listview1");
var columns = lv.columns;

columns.GetColumnAt(0).width = 235;
columns.GetColumnAt(1).width = 60;
columns.GetColumnAt(2).width = 235;
columns.GetColumnAt(3).width = 60;