How to get selected listview items with RunDlg

I'm trying to get user selected items from a listview with the simpler method without event loops as I don't need any real-time reactions, so I run an "attached" dialog

var Dlg = clickData.func.Dlg; Dlg.window = tab; Dlg.template = "Tabs";
Dlg.Create(); // create a detached
///... configure dialog
var retVal = Dlg.RunDlg(); // run as attached

But then I can't accessDlg.Control anymore after I get a return value.
So this

  var lvtest = Dlg.Control('ctrlname');
  p("pre f lvtest # " + lvtest.count); // works
  var retVal = Dlg.RunDlg();
  var lvtest = Dlg.Control('ctrlname'); // fails
  p("pos f lvtest # " + lvtest.count); 

Am I correct that it's simply destroyed? And how can I get the selection items at the moment of destruction?

It's much easier to answer this kind of question if you post code that is complete enough to run.

(Remove any unnecessary details, but keep enough so we can actually run it to see what's happening and try changing things.)

here is the example button

_t.dcf (2.6 KB)

The control no longer exists once RunDlg returns so most properties don't work, but you should still be able to get information about which items were selected.

I agree I should be able to get the info :slight_smile: but how? Where is this data stored?

Reading Dialog Control Values [Directory Opus Manual] tells me that

in both a simple and a detached dialog you can also do this after the dialog has closed.

The Dialog.Control method is used


After the user has closed the dialog the Control object can be used to obtain the final value of each control.

This is exactly what I need - the final value!

Have you tried the control’s value property?

Oh, so the control still exists (or maybe not :), see below) ! I'm getting some values from .value will try that, thanks!

Hm, for multiselected listview I thought I'd get a value of listitems, but I only get a vector of ints

Note that for a multiple-selection list box or list view , this value will return a Vector of DialogListItem objects, representing all currently selected items

Is it because those items are destroyed?

Hard to guess what's wrong if you don't show us the code, but this works:

  var retVal = Dlg.RunDlg();
  var sel = Dlg.Control('lv1').value;
  DOpus.Output("TypeOf sel = " + DOpus.TypeOf(sel));
  for (var i = 0; i < sel.count; ++i)
  	DOpus.Output("Selected " + i + " = " + sel(i).name);