maybe there is a solution without the listview controls that seem to cause some issues. You could create a wrapper object and create a onclick action on you listview that associates/unassociates the clicked element in the Listview with your wrapper. If you are done with selecting elements you could pass this wrapper object to your document template.
Can you give some more information? Where do you use the list view controls? What does the microflow with your document template action look like?
In general you have to pass or retrieve the selected rows in a microflow. Then in this microflow you pass this data to the document template. The setup of the document template defines what data needs to be the input.
Looking at your screenshots, what i think you should be doing is as follows:
One or more of the treatmenthistory objects are selected by the user. They are linked to the contacts object. In the template document you have problably placed a datagrid with the treatment history. If you place this datagrid outside of a dataview in the template grid it becomes available als a list parameter.
What you then need to do is retrieve the treatmenthistory objects linked to the contacts that have the select boolean as true. You can either do this with a xpath retrieve(first commit the treamtent history) or with a list operation ‘Filter’. The filtered list can be set as a parameter for the documenttemplate and then you will have your result:)