在多列列表框顶部添加项目 [英] Add item at top of multi column listbox
本文介绍了在多列列表框顶部添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了一些有关插入函数的信息,但是在Excel VBA中似乎不可用.
I found some information about insert function but it seems to be not available in Excel VBA.
我创建了一个FOR,它将每行移到+1位置,然后在0索引处插入项目.
I create a FOR which will move each row to +1 position and then insert item at 0 index.
是否有更简单的方法在多列列表框的开头添加项目?
Is there an easier way to add an item at the beginning of a multi column listbox?
我的版本如下:
Sub InsertRecordAtTheTop(sText1, sText2)
Dim i
With lbCases
If .ListCount > -1 Then
.AddItem "0" ''' add new row
For i = .ListCount - 1 To 1 Step -1 ''' move everything +1 postion
.List(i, 0) = .List(i - 1, 0)
.List(i, 1) = .List(i - 1, 1)
.List(i, 2) = .List(i - 1, 2)
.List(i, 3) = .List(i - 1, 3)
.List(i, 4) = .List(i - 1, 4)
Next i
.List(0, 0) = sText1 ''' paste new values at top
.List(0, 1) = sText2
.List(0, 2) = ""
.List(0, 3) = ""
.List(0, 4) = ""
Else
.AddItem sText1 ''' if listbox is empty, just paste
.List(0, 1) = sText2
End If
End With
End Sub
推荐答案
AddItem
使用可选参数来指定索引位置.默认情况下,它添加到末尾.如果指定0,它将在开头添加.尝试类似的东西:
AddItem
takes an optional parameter to specify the index position. By default it adds to the end. If you specify 0 it will add at the beginning. Try Something like:
.AddItem "Some Text", 0
可以在此中找到更多信息.MSDN 文章.
这篇关于在多列列表框顶部添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文