2016-06-23 30 views
0

我有一個同事在useform中創建的多列listview。一旦使用表單打開,它就會被填充。我想查找填充列表視圖最後一行中的項目。例如:查找多列列表視圖的最後一項

header1 header2 header3 
11   12  13 
21   22  23 
31   32  33 

我想的線(或幾行)來存儲3132,和33在單獨的變量。

我的ListView被命名爲lsvLots。我能在String strProduct存儲31通過以下方式:

strProduct = lsvLots.ListItems.Item(lsvLots.ListItems.Count) 

HoweverI只能返回第一個欄的最後一個項目的方式。我怎樣才能訪問其他列?

回答

2

在列表的最後一行是由ListCount確定,可以參考如下:

UserForm1.lsvLots.List(UserForm1.lsvLots.ListCount - 1, 0) 

注意,該ListCount將是1,如果有一個行列表框中。然而,引用該索引(第一行&最後一行)的索引從0開始,而不是從1開始。因此,您必須從ListCount中減去1以將其轉換爲索引(從0開始)。

最後的0表示您希望從該行獲得第一列。再次,列第一列,1爲第二列,2第三列是0,等等

總之,爲了從最後一排的所有項目,你應該使用:

strProduct1 = UserForm1.lsvLots.List(UserForm1.lsvLots.ListCount - 1, 0) 
strProduct2 = UserForm1.lsvLots.List(UserForm1.lsvLots.ListCount - 1, 1) 
strProduct3 = UserForm1.lsvLots.List(UserForm1.lsvLots.ListCount - 1, 2) 

OR(待整理):

With UserForm1.lsvLots 
    strProduct1 = .List(.ListCount - 1, 0) 
    strProduct2 = .List(.ListCount - 1, 1) 
    strProduct3 = .List(.ListCount - 1, 2) 
End With 
0

試試這個

​​