Script list with checkboxes in second column?

[ Topic split from Filter box in the list dialog ]


How to add line number? I'll keep searching the forum when I have time. . .

function OnClick(clickData)
{

    var strValue, strNewValue;
    var strName;

    var dlg = DOpus.Dlg;

    dlg.title = "Directory Opus";
    dlg.template = "dlgList";
    dlg.detach = true;
    dlg.Create();
	dlg.Control("static2").label = "D:\\Icons\\XYplorer Search Find.png";
	dlg.Control("static3").label = "D:\\Icons\\XYplorer Search Find.png";

    updateList(dlg, strName, strValue);

    dlg.Show();



    while (true) {
        var msg = dlg.GetMsg();
        if (!msg.result) break;
//New
        if (dlg.Control("btnOK").focus == true) {
            for (i=0; i < dlg.Control("list").count; i ++) {
                if (dlg.Control("list").GetItemAt(i).checked == 1) {
					DOpus.Output(dlg.Control("list").GetItemAt(i).name);
                }
            }
		}

//Right click list menu
        if (msg.event == "rclick" && dlg.Control("list").focus == true) {

            var dlgMenu = DOpus.Dlg;
            if (dlg.Control("list").value.index > -1) {
                //dlgMenu.choices = DOpus.Create.Vector("Edit...", "Delete", "-", "Select Variable", "Deselect Variable", "-", "Select All", "Select None", "-", "Copy Name", "Copy Value", "-", "Clear Filter", "Refresh");
				dlgMenu.choices = DOpus.Create.Vector("OK", "Cancel");
                //dlgMenu.menu = DOpus.Create.Vector(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
				dlgMenu.menu = DOpus.Create.Vector(1, 1);
            }
            else {
                //dlgMenu.choices = DOpus.Create.Vector("New...", "Delete", "-", "Select Variable", "Deselect Variable", "-", "Select All", "Select None", "-", "Copy Name", "Copy Value", "-", "Clear Filter", "Refresh");
				dlgMenu.choices = DOpus.Create.Vector("OK", "Cancel");
                dlgMenu.menu = DOpus.Create.Vector(1,1);
            }
            var menuReturn = dlgMenu.Show;

        }
//Filter
		if (msg.event == "editchange" || msg.event == "click") {
			updateList(dlg, strName, strValue);
		}

    }
}

function updateList(dlg, strName, strValue) {

    dlg.Control("list").RemoveItem(-1);

//New
    var text = "tag1, tag2, tag3, tag4, tag5, tag6";
	var myArray = text.split(", ");
    for(i = 0; myArray[i]; i++) {
        strName = myArray[i];
		var strRealName = myArray[i];
		
		var strFilter = dlg.Control("editFilter").value;
		strFilter = strFilter.toLowerCase();

		if (strRealName.search(strFilter) == -1) {
			continue;
		}

        dlg.Control("list").AddItem(strName);

        if (strName.persist == true) {
            dlg.Control("list").GetItemByName(strName).subitems(2) = "yes";
        }
        else dlg.Control("list").GetItemByName(strName).subitems(2) = "no";

		strRealName = "";
		strFilter = "";
    }
    dlg.Control("list").columns.AutoSize();
	//dlg.Control("staticNotify").label = "Total: " + dlg.Control("list").count;
}



==SCRIPT RESOURCES
<resources>
	<resource name="dlgList" type="dialog">
		<dialog fontsize="8" height="388" lang="english" resize="yes" title="Global Vars - Directory Opus" width="325">
			<control halign="left" height="14" name="editFilter" resize="w" tip="Filter" type="edit" width="118" x="28" y="364" />
			<control checkboxes="auto" fullrow="yes" height="317" name="list" resize="wh" smallicons="yes" type="listview" viewmode="list" width="308" x="8" y="39">
				<columns>
					<item text="Name" />
					<item text="Value" />
					<item text="Type" />
					<item text="Persist" />
				</columns>
			</control>
			<control close="0" height="14" name="btnOK" resize="xy" title="&amp;OK" type="button" width="50" x="213" y="363" />
			<control close="0" height="14" name="btnClose" resize="xy" title="C&amp;ancel" type="button" width="50" x="266" y="363" />
			<control halign="left" height="18" name="static" title="Find by Tags" type="static" valign="top" width="279" x="36" y="10" />
			<control halign="left" height="14" image="yes" name="static2" title="Static" type="static" valign="top" width="14" x="10" y="12" />
			<control halign="left" height="14" image="yes" name="static3" title="Static" type="static" valign="top" width="14" x="11" y="364" />
		</dialog>
	</resource>
</resources>

Is it possible?

It's a List View control so you can add whatever columns you want to the list, and populate them with whatever values you want.

There is a Columns property in the dialog editor which lets you define which columns the list has (but not the values in them), or you can set them up in code.

I think you will need to use code to populate the column values. That can be done using DialogListItem.subitems.

Note that Windows only allows checkboxes on the main column (column zero), but the columns can be displayed in any order, so you can display column 1 and then column 0 if you want that.

Thanks, but I haven't figured out how to do that yet.

DialogListColumns seems a good place to start. It is almost next to the DialogListItem object I linked above.

I tried it a few hours ago and I don't know how to use it... There are less search results.

Make sure I understand correctly: Display column 1 and then column 0, checkboxes will on the second column (colmun 0)?

That’s right.

I did some tests and still can't get column 0 display in the second column. :disappointed_relieved:
image
Adding multi-column items in List View - Help & Support - Directory Opus Resource Centre (dopus.com)

function OnClick(data)
{
	var msg;
	var dlg = DOpus.Dlg;
	dlg.window = DOpus.Listers(0);
	dlg.template = "dlgList";
	dlg.detach = true;
	dlg.Show();

	var lst = dlg.Control("list");
	lst.value = false;
	var col = lst.columns;
	col.AddColumn("Item");
	col.AddColumn("Subitem 0");
	col.AddColumn("Subitem 1");
//Test
	col.InsertColumn("Index", 0);
	//col.InsertColumn("Index", 1);
	lst.AddItem("Test");
	item0 = lst.GetItemAt("Test").name;
	lst.GetItemByName(item0).subitems(0) = "Test2";

	col.AutoSize();

	do	// msg loop
	{
		msg = dlg.GetMsg();
		if (msg.event == "click" && msg.control == "button1")
		{
			var pos = lst.AddItem("Item " + lst.count);
			var lst_item = lst.GetItemAt(pos);
			lst_item.subitems(0) = "Subitem 0";
			lst_item.subitems(1) = "Subitem 1";
		}
	} while (msg == true);
}



==SCRIPT RESOURCES
<resources>
	<resource name="dlgList" type="dialog">
		<dialog fontsize="8" height="388" lang="english" resize="yes" title="Global Vars - Directory Opus" width="325">
			<control halign="left" height="14" name="editFilter" resize="w" tip="Filter" type="edit" width="118" x="28" y="364" />
			<control checkboxes="auto" fullrow="yes" height="317" name="list" resize="wh" type="listview" viewmode="details" width="308" x="8" y="39">
				<columns>
					<item text="Name" />
					<item text="Value" />
					<item text="Type" />
					<item text="Persist" />
				</columns>
			</control>
			<control close="0" height="14" name="btnOK" resize="xy" title="&amp;OK" type="button" width="50" x="213" y="363" />
			<control close="0" height="14" name="btnClose" resize="xy" title="C&amp;ancel" type="button" width="50" x="266" y="363" />
			<control halign="left" height="18" name="static" title="Find by Tags" type="static" valign="top" width="279" x="36" y="10" />
			<control halign="left" height="14" image="yes" name="static2" title="Static" type="static" valign="top" width="14" x="10" y="12" />
			<control halign="left" height="14" image="yes" name="static3" title="Static" type="static" valign="top" width="14" x="11" y="364" />
		</dialog>
	</resource>
</resources>

It turns out the Windows listview control requires doing something special to put a column before the first one.

In the next update, we'll add a new SetDisplayOrder method which allows this:

function OnClick(clickData)
{
	var dlg = clickData.func.dlg;
	dlg.template = "dlgList";
	dlg.detach = true;
	dlg.Show();

	var lst = dlg.Control("list");
	var col = lst.columns;
	col.AddColumn("0:Name");
	col.AddColumn("1:Index");
	col.AddColumn("2:Blah");

	var idx;

	idx = lst.AddItem("Name 1");
	lst.GetItemAt(idx).subitems(0) = "Index 1";
	lst.GetItemAt(idx).subitems(1) = "Blah 1";

	idx = lst.AddItem("Name 2");
	lst.GetItemAt(idx).subitems(0) = "Index 2";
	lst.GetItemAt(idx).subitems(1) = "Blah 2";

	if (false)
	{
		// Can do it like this...
		var vecOrderIn = DOpus.Create.Vector();
		vecOrderIn.push_back(1);
		vecOrderIn.push_back(0);
		vecOrderIn.push_back(2);
		col.SetDisplayOrder(vecOrderIn);
	}
	else
	{
		// ...or like this.
		col.SetDisplayOrder(1,0,2);
	}

	col.AutoSize();

	// Can also query the current display order.
	var vecOrder = col.GetDisplayOrder();
	for (var i = 0; i < vecOrder.size; ++i)
	{
		DOpus.Output("Order: " + vecOrder(i));
	}

	while (true)
	{
		var msg = dlg.GetMsg();
		if (!msg.result) break;
	}
}
<resources>
	<resource name="dlgList" type="dialog">
		<dialog fontsize="8" height="138" lang="english" resize="yes" standard_buttons="ok,cancel" title="Test" width="318">
			<control checkboxes="auto" fullrow="yes" height="111" name="list" resize="wh" type="listview" viewmode="details" width="306" x="6" y="6" />
		</dialog>
	</resource>
</resources>

Docs for the two new DialogListColumns methods which will be added in 12.30.1 beta.

(This will be added to the manual, but may not be added until after the stable release.)

BTW: It would be nice to increase the spacing between each line, e.g. +5px. It's currently a bit crowded and not easy to read when there are multiple lines.

One thing per thread, please. I've already split this thread once to separate unrelated things. :slight_smile:

(But line spacing is generally down to Windows and the font in use. The list controls have standard spacing which we aren't overriding here, and should be the same as in any other standard listview with the same font.)

Okay, that's not important, so I didn't start a new topic. . .

BTW: It would be nice to increase the spacing between each line, e.g. +5px. It's currently a bit crowded and not easy to read when there are multiple lines.

I forgot I switched to list view mode last time (Face palm), details view mode spacing is normal.