如何获取列表中的所有项目?
函数“CustomFieldValueListGetItem”仅通过索引获取元素。
我不知道最后一个索引。找不到返回它的此类属性或函数。有没有像“GetAllItems as Array or Collection”这样的函数? (MSDN 没有帮助)
因此,为了实现这一点,我编写了代码,它有效,但我不喜欢它。
Dim MSPApp = oProjAct.Application
Dim GetStr As String
Dim CurrentArray(0)
For y = 1 To 1500
Try
GetStr = MSPApp.CustomFieldValueListGetItem(PjCustomField.pjCustomTaskText2, PjValueListItem.pjValueListValue, y)
ReDim Preserve CurrentArray(UBound(CurrentArray) + 1)
CurrentArray(UBound(CurrentArray)) = GetStr
Catch
Exit For 'so if error - that's the last item.
End Try
Next
CustomFieldValueListGetItem 方法,用于访问自定义字段列表值的隐藏集合对象。
这是代码的一个变体,至少读起来更好一点:
Dim ListValues As New List(Of String)
Try
Dim idx As Int32 = 0
Do While True AndAlso idx < 10000
idx += 1
ListValues.Add(ProjApp.CustomFieldValueListGetItem(PjCustomField.pjCustomTaskText2, PjValueListItem.pjValueListValue, idx))
Loop
Catch NoMoreItems As System.Exception
End Try