How to set the Checked property of a ListView control

line 16 error: 'Dlg.control(...).GetItemByName(...).checked' (0x800a0005)

Option Explicit
Function OnClick(ByRef clickData)
	dim Dlg, Msg, str
    Set Dlg = DOpus.Dlg
    Dlg.window = clickData.func.sourcetab
    Dlg.template = "dialog1"
    Dlg.detach = True
    Dlg.Show 
	Do
    	Set Msg = Dlg.GetMsg()
		if Msg.Event = "click" and Msg.control = "button1" then
			str = "scriptadd" & Random(1,100)
			Dlg.Control("listview1").AddItem str, 1
			dopus.output Dlg.Control("listview1").GetItemByName(str).name
			dopus.output "checked = " & Dlg.Control("listview1").GetItemByName(str).checked
			Dlg.Control("listview1").GetItemByName(str).checked = true
		end if
	Loop While Msg

End Function
function Random(nLow, nHigh)
    Randomize
    Random = Int((nHigh - nLow + 1) * Rnd + nLow)
End function

<resources>
	<resource name="dialog1" type="dialog">
		<dialog fontsize="8" height="186" lang="english" width="144">
			<control checkboxes="auto" height="156" name="listview1" type="listview" viewmode="list" width="132" x="6" y="24">
				<contents>
					<item text="桔子" />
					<item text="苹果" />
					<item text="香蕉" />
				</contents>
			</control>
			<control height="14" name="button1" title="按钮" type="button" width="50" x="12" y="6" />
		</dialog>
	</resource>
</resources>

GetItemByName returns a DialogListItem. That has no checked property, but there is a selected one, which may be what you want.

Selected property is not what I want.

Support for Listview checks was only added in the 12.7.1 beta which is why it's not mentioned in the online help yet.

The problem is that true isn't a valid value for checked in that context. These are the values you can use:

  • 0 = unchecked
  • 1 = checked
  • 2 = indeterminate
  • 3 = unchecked, disabled
  • 4 = checked, disabled
  • 5 = indeterminate, disabled