MS 项目。 VB、VB.NET。 Application.CustomFieldValueListGetItem - 如何获取所有项目?

问题描述 投票:0回答:2

如何获取列表中的所有项目?

函数“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
    
vb.net ms-project
2个回答
0
投票
不幸的是,Project 对象模型没有提供可用作循环基础的 count 属性。因此,有时您只需要“短打”,这就是您使用简单代码所做的事情。它有效,享受它,然后继续前进。


0
投票
如前所述,由于 API 中没有公开集合对象,因此没有 Count 方法。所有 API 提供的都是

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
    
© www.soinside.com 2019 - 2024. All rights reserved.