Adding a DialogItem object from one listview to another doesn't work

A small test:


// Called by Directory Opus to initialize the script
function OnInit(initData) {
	initData.name = "copy_item_test";
	initData.version = "1.0";
	initData.copyright = "(c) 2024 Cris";
	//	initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "13.0";

}

// Called to add commands to Opus
function OnAddCommands(addCmdData) {
	var cmd = addCmdData.AddCommand();
	cmd.name = "CDI";
	cmd.method = "OnCDI";
	cmd.desc = "";
	cmd.label = "CDI";
	cmd.template = "";
	cmd.hide = false;
	cmd.icon = "script";
}

// Implement the CDI command
function OnCDI(scriptCmdData) {
	var dlg = scriptCmdData.func.dlg;
	dlg.template = 'dialog1';
	dlg.Create();
	var msg, row;
	var list1 = dlg.control('listview1');
	var list2 = dlg.control('listview2');
	list1.EnableGroupView(true);
	list2.EnableGroupView(true);
	list1.AddGroup('test1', 0);
	list1.AddGroup('test2', 1);
	list2.AddGroup('test1', 0);
	list2.AddGroup('test2', 1);

	for (var i = 0; i < 5; i++) {
		row = list1.getItemAt(list1.AddItem('Dummy ' + i, 0, 1)); // Add to test2 group
		row.subitems(0) = i;
	}
	dlg.Show();
	while (true) {
		msg = dlg.GetMsg();
		if (!msg.result) break;
		if (msg.control == 'button1') {

			for (var i = 0; i < list1.count; i++) {
				row = list1.getItemAt(i);
				DOpus.Output(row.name + ':' + row.group);
				list2.AddItem(row); //doesn't work
			}
			DOpus.Output('list2:'+list2.count);
		}
	}
}

copy_item_test.opusscriptinstall (1.4 KB)

Whenever I try to copy the items from 'list1' to 'list2', nothing visible happens, 'list2' remains empty. However, the count property for the Control object indicates that the items were actually added.
As a side note, whenever I copy with groups disabled, it seems to work, but it only copies the first column, if there's more than one.

Have you tried creating real DialogItem to populate the first listview instead of using the AddItem with a name ?
EDIT : Scratch that, it does not seem possible to create them directly.

The problem comes from the list being set to grouped mode. In grouped mode, items that aren't assigned to a group aren't shown by the control, and when you pass an existing item to AddItem it doesn't assign the new item to a group.

In the next beta we'll add the ability to specify a group when adding an item from an existing item (rather than just from a string).

2 Likes

Interesting. Thanks for checking it out.
A bit offtopic, but very related to the topic, to add a filtering function to a list, generally all the items are removed and then those that you want to display are added back.

  • In a grouped mode, would moving them to an unlisted group also hide them?
  • To easy up this feature (filtering a list), some way could be added to simply show/hide an item?. Thus speeding up the filtering process, whether the list is in grouped mode or not.

Again, many thanks.

It would, although currently via our scripting model there's no way to change an item's group once it has been added.

The underlying Windows list view control doesn't support that, unfortunately.

Thanks. Now the item is visible in the 'target' listview.
But, it seems that only the first column is passed. Is there any way to pass the complete to another listview the complete item's content (including all the columns)?

In 13.10.3 all columns will be copied.

1 Like

Many thanks!