GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Msg.event "selchange" fired twice for ListView



In a detached dialog, listview selection change selchange will fire a msg event two times instead of expected once: the very first item selection will produce only a single event containing the data of the selected item (as expected), but subsequent item selections will produce two events in sequence: one for deselection of old item, and one for selection of new item (with their corresponding data). Furthermore, the true deselection (click on empty space to deselect items) will fire only deselect selchange event. That's quite unexpected and undocumented behavior. One would expect that selchange always gives data of newly selected item.

function OnClick(clickData)
	var dlg = clickData.func.Dlg;
	dlg.template = "dialog1";
	dlg.Create(); // Detach (so that we can access our custom controls defined in the resource XML).
	var msg = true;
	while (msg == true)
		msg = dlg.GetMsg();
		if (msg == true)
			if (msg.event == "selchange")

I guess we'd need an additional property to determine in what way the selection got changed so we could filter further in our loop. For now, I've placed the last value variable in my code to filter out the deselection event, but I feel it's a hacky solution.

The minimum test button is attached:
Test.dcf (2.2 KB)


SelChange means a selection has changed. It tells you both selection and deselection. Everything there is as intended (and mirrors the way the Windows API works).