Did you check the properties for $did in the help file.
lines returns number of lines
$did(name,id).lines

And to load back the last selected item you would need to store the item in a variable , ini or hash table then use the c switch in the dialog init event