Listview wont show grouped items

I am trying to group items in a listview in a dialog.
Populating the listiview with ungrouped items does work flawlessly.
When trying to add groups to the listview and assigning items to these groups, the listview is empty.
The example i found is this one https://resource.dopus.com/t/listview-groups/35842/2
The groups are generated first, then EnableGroupView(true); gets called. The example works for me, however i was not able to get my code to show the grouped items and could need some help :innocent:

function OnClick(clickData)
{
	oneLoop(clickData);
	twoLoops(clickData);
}


function oneLoop(clickData)
{
var dlg = DOpus.Dlg;
	dlg.window = clickData.func.sourcetab;
	dlg.template = "SourcePicker";
	dlg.detach = true;
	dlg.Create();
	
	var listView = dlg.Control("lvSources");
	var buttonOK = dlg.Control("buttonOK");
	var allItemsSelected = false;
	var itemCount = 0;
	var folderCandidates = [];

	var dcimPaths = ["Z:\\DCIM"];
	var mediaFolders =["102NZ6_2", "103NZ6_2"];


//adding´groups and items 
	for(var i = 0; i < dcimPaths.length; i++)
	{
		var dcimPath = dcimPaths[i];
		var group = dlg.Control("lvSources").AddGroup(String(i), i);
		for(var j = 0; j < mediaFolders.length; j++)
		{
			//var fsItem = DOpus.FSUtil.GetItem(mediaFolders[i])
			var addedIndex = dlg.Control("lvSources").AddItem(mediaFolders[j], itemCount, group);
			/*
			var lvItem = dlg.Control("lvSources").GetItemAt(addedIndex);
			lvItem.subitems(0) = fsItem.create.Format("D#yyyy-MM-dd T#HH-mm-ss");
			lvItem.subitems(1) = fsItem.modify.Format("D#yyyy-MM-dd T#HH-mm-ss");
			lvItem.subitems(2) = CountFolderMembers(fsItem);	
			*/
			itemCount++;
		}
	}
	listView.columns.AutoSize();
//enabling groupview
	dlg.Control("lvSources").EnableGroupView(true);

	dlg.Show();
	while (true) 
	{
        var msg = dlg.GetMsg();
        if (!msg.result) 
			break;

		DOpus.Output("Msg Event = " + msg.event + " by " + msg.control);
		if (msg.event == "click")
		{
			if(msg.control == "buttonOK")
			{
				return;
			}
		}
	}
}

function twoLoops(clickData)
{
	var dlg = DOpus.Dlg;
	dlg.window = clickData.func.sourcetab;
	dlg.template = "SourcePicker";
	dlg.detach = true;
	dlg.Create();
	
	var listView = dlg.Control("lvSources");
	var buttonOK = dlg.Control("buttonOK");
	var allItemsSelected = false;
	var itemCount = 0;
	var folderCandidates = [];

	var dcimPaths = ["Z:\\DCIM"];
	var mediaFolders =["102NZ6_2", "103NZ6_2"];

//adding groups
	for(var i = 0; i < dcimPaths.length; i++)
	{
		var dcimPath = dcimPaths[i];
		var group = dlg.Control("lvSources").AddGroup(String(i), i);
	}
//enabling groupview
	dlg.Control("lvSources").EnableGroupView(true);

//adding items to groups
	for(var i = 0; i < dcimPaths.length; i++)
	{
		var dcimPath = dcimPaths[i];
		for(var j = 0; j < mediaFolders.length; j++)
		{
			//var fsItem = DOpus.FSUtil.GetItem(mediaFolders[i])
			var addedIndex = dlg.Control("lvSources").AddItem(mediaFolders[j], itemCount, i);//originally used the var "group" instead of i when i had just one loop
			/*
			var lvItem = dlg.Control("lvSources").GetItemAt(addedIndex);
			lvItem.subitems(0) = fsItem.create.Format("D#yyyy-MM-dd T#HH-mm-ss");
			lvItem.subitems(1) = fsItem.modify.Format("D#yyyy-MM-dd T#HH-mm-ss");
			lvItem.subitems(2) = CountFolderMembers(fsItem);	
			*/
			itemCount++;
		}
	}
	listView.columns.AutoSize();

	dlg.Show();
	while (true) 
	{
        var msg = dlg.GetMsg();
        if (!msg.result) 
			break;

		DOpus.Output("Msg Event = " + msg.event + " by " + msg.control);
		if (msg.event == "click")
		{
			if(msg.control == "buttonOK")
			{
				return;
			}
		}
	}
}


	<resource name="SourcePicker" type="dialog">
		<dialog fontsize="8" height="108" lang="english" title="Select source folders" width="498">
			<control fullrow="yes" height="84" multisel="yes" name="lvSources" sort="yes" type="listview" viewmode="details" width="490" x="3" y="3">
				<columns>
					<item text="Path" />
					<item text="Created" />
					<item text="Modified" />
					<item text="Children" />
				</columns>
			</control>
			<control default="yes" enable="no" height="14" name="buttonOK" title="OK" type="button" width="50" x="3" y="91" />
			<control close="0" height="14" name="buttonCancel" title="Cancel" type="button" width="50" x="444" y="91" />
			<control height="14" name="buttonSelectAll" title="De/select all" type="button" width="93" x="154" y="91" />
			<control height="14" name="buttonSelectAllAndContinue" title="De/select all and continue" type="button" width="93" x="251" y="91" />
		</dialog>
	</resource>

Have you tried doing the same thing? i.e. Move the EnableGroupView call to after the point the groups are added. If that's the difference between the working example and non-working code, it's what I'd try first.

Yes, the code above is already the adapted code. I originally had only one loop over "dcimPaths".
Right now there is one loop for adding the groups, then the EnableGroupView call and then adding the items in another loop. The only difference i see is that the example does not have loops instead the items are added manually.

You're calling AddGroup in both loops.

Thats true, must have been messing up copying the code. The second call was my original approach and then using the result of addgroup() for additem()

Added both non working versions where EnableGroupView gets called from different locations.

I have added two examples with different locations from where EnableGroupview is being called but both do not work.

@Leo after many hours I came to a solution:
The reason is that AddGroup() does not accept a 0 as ID for a group.

This is only implicitly shown in Jons example, but I was not able to find it in a explicitly written version, so I ask you to adjust the docs or the code to accept a 0 based id (which would be resonable for a 0 Index based language).
Also EnableGroupView(true) has to be called before adding items to groups.

So this code works

	for(var i = 0; i < groups.length; i++)
	{
		var group = dlg.Control("lvSources").AddGroup(String(i), i+1);
	}
	dlg.Control("lvSources").EnableGroupView(true);

We'll fix that in 12.25.1 beta. Thanks for tracking it down!

FWIW, in my testing it only left out items added to the group with id zero (which was being treated as "no group" by the AddItem/InsertItem methods), so if there were any other groups their items should still have shown up.

We'll change it so items only have "no group" if the group number isn't specified at all.

1 Like

Youre welcome and thanks for the fix.

Yes, in retrospective i have to admit that I tried it in the "real usecase situation" where I always had just one group that would have been displayed, didnt think about that.

Sounds good :+1:

Blockquote