'listview selection selected
'   在列表视图中设置当前项的选择位置。
'   例如，它在报告模式下设置ListView中突出显示的行的行号。
'   hWndControl: 控件的句柄 (例如  HWND_FORM1_LISTVIEW1)
'   nIndex:      要选择的项的从零开始的索引。  
'   Returns:     以前的选择标记，如果没有以前的选择标记返回-1值。
Function FF_ListView_SetSelectedItem(ByVal hWndControl as HWnd, ByVal nIndex as Long) as Long
   
   '检查窗口句柄是否有效
   If IsWindow(hWndControl) Then
      Function = SendMessage(hWndControl, LVM_SETSELECTIONMARK, 0, nIndex)
      
      'ensure that the item is set visually as well
      Dim tItem as LVITEM
      tItem.mask = LVIF_STATE
      tItem.iItem = nIndex
      tItem.iSubItem = 0
      tItem.State = LVIS_FOCUSED Or LVIS_SELECTED
      tItem.statemask = LVIS_FOCUSED Or LVIS_SELECTED
      SendMessage hWndControl, LVM_SETITEMSTATE, nIndex, Cast(LPARAM, VarPtr(tItem))
   End If
   
End Function

