# Listview wont show grouped items

**URL:** <https://resource.dopus.com/t/listview-wont-show-grouped-items/39356>\
**Category:** Help & Support\
**Tags:** script, jscript\
**Created:** [September 19, 2021, 10:45am UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356 "2021-09-19T10:45:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felix.Froemel](https://resource.dopus.com/user_avatar/resource.dopus.com/felix.froemel/32/68705_2.png) [@Felix.Froemel](https://resource.dopus.com/u/Felix.Froemel)\
**Post date:** [September 19, 2021, 10:45am UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/1 "2021-09-19T10:45:30Z")

</div>

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](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 😇

```auto
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;
			}
		}
	}
}

```

```auto
	<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>

```

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [September 19, 2021, 10:56am UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/2 "2021-09-19T10:56:57Z")

</div>

> [@Felix.Froemel](#):
>
> The groups are generated first, then `EnableGroupView(true);` gets called. The example works for me

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.

---

<div class="post-metadata">

**Author:** ![Felix.Froemel](https://resource.dopus.com/user_avatar/resource.dopus.com/felix.froemel/32/68705_2.png) [@Felix.Froemel](https://resource.dopus.com/u/Felix.Froemel)\
**Post date:** [September 19, 2021, 11:02am UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/3 "2021-09-19T11:02:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [September 19, 2021, 11:04am UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/4 "2021-09-19T11:04:29Z")

</div>

You're calling AddGroup in both loops.

---

<div class="post-metadata">

**Author:** ![Felix.Froemel](https://resource.dopus.com/user_avatar/resource.dopus.com/felix.froemel/32/68705_2.png) [@Felix.Froemel](https://resource.dopus.com/u/Felix.Froemel)\
**Post date:** [September 19, 2021, 11:08am UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/5 "2021-09-19T11:08:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Felix.Froemel](https://resource.dopus.com/user_avatar/resource.dopus.com/felix.froemel/32/68705_2.png) [@Felix.Froemel](https://resource.dopus.com/u/Felix.Froemel)\
**Post date:** [September 19, 2021, 12:52pm UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/6 "2021-09-19T12:52:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Felix.Froemel](https://resource.dopus.com/user_avatar/resource.dopus.com/felix.froemel/32/68705_2.png) [@Felix.Froemel](https://resource.dopus.com/u/Felix.Froemel)\
**Post date:** [September 19, 2021, 7:45pm UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/7 "2021-09-19T19:45:27Z")

</div>

@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

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

```

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [September 20, 2021, 12:27pm UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/8 "2021-09-20T12:27:53Z")

</div>

> [@Felix.Froemel](#):
>
> The reason is that `AddGroup()` does not accept a `0` as ID for a group.

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.

---

<div class="post-metadata">

**Author:** ![Felix.Froemel](https://resource.dopus.com/user_avatar/resource.dopus.com/felix.froemel/32/68705_2.png) [@Felix.Froemel](https://resource.dopus.com/u/Felix.Froemel)\
**Post date:** [September 20, 2021, 7:06pm UTC](https://resource.dopus.com/t/listview-wont-show-grouped-items/39356/9 "2021-09-20T19:06:00Z")

</div>

> [@Leo](#):
>
> We'll fix that in 12.25.1 beta. Thanks for tracking it down!

Youre welcome and thanks for the fix.

> [@Leo](#):
>
> 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.

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.

> [@Leo](#):
>
> We'll change it so items only have "no group" if the group number isn't specified at all.

Sounds good 👍

> Blockquote
