DialogListItem.data not working

Hi
i am trying to add data to a DialogListItem in a (grouped) listview.
This can be done in listview.AddItem by passing the data as 2nd parameter or later on via item.data (which is a getter and setter) see Control Docs and DialogListItem Docs

I am handing the data over in the AddItem method. Then (for test purposes) i try to retrieve the item again via its index. The name of the item is correct, but its data is 0 (even if i try this after showing the dialog).
And if i try to set the data via item.data, i get an A method was called unexpectedly (0x8000ffff) error.

Listviewitem data test.dcf (3.7 KB)

function OnClick(clickData)
{
	var dlg = clickData.func.Dlg;
	dlg.template = "dialog1";
	dlg.Create();

	var listview = dlg.Control("listview");
	var groups = ["Dates", "Sepcial"];
	for(var i = 0; i < groups.length; i++)
	{
		var group = groups[i];
		var createdGroup = listview.AddGroup(group, i);
		var addedAtIndex = listview.AddItem("Itemname in " + group, "Data " + i, i);
		var retrievedItem = listview.GetItemAt(addedAtIndex);
		Log("Item Name: " + retrievedItem.name);
		Log("Item Data: " + retrievedItem.data);//This is always 0
			
		//DialogListItem.data Returns or sets the optional data value associated with this item.
		//retrievedItem.data = "new try"; //not allowed: A method was called unexpectedly (0x8000ffff)

	}
	listview.EnableGroupView(true);
		
	Log("\n\nNew try\n\n");	
	
	dlg.Show();//no matter if before or after the 2nd loop
	for(var i = 0; i < groups.length; i++)
	{
		var retrievedItem = listview.GetItemAt(i);
		Log("Item Name: " + retrievedItem.name);
		Log("Item Data: " + retrievedItem.data);
	}
	//dlg.Show();//could also be here

}

function Log(msg) { DOpus.Output(String(msg)); }

This code produces the following output

Item Name: Itemname in Dates
Item Data: 0
Item Name: Itemname in Sepcial
Item Data: 0
New try
Item Name: Itemname in Dates
Item Data: 0
Item Name: Itemname in Sepcial
Item Data: 0

Expected ouput for data should be Data 0 or Data 1

You are passing a string as the data value. The documentation says it takes an integer.

1 Like

Thanks, seems that my brain is in vacation in contrast to me, sorry for two unnecessary posts from my side an thanks for helping me (to read properly) :sweat_smile:
Have nice holidays and a healty start to the new year๐ŸŽ‰

1 Like