AllowDrop

逻辑型,是否允许在ListView接收拖动过来的行。

示例

Dim lvw As WinForm.ListView = e.Form.Controls("ListView1")
lvw
.AllowDrag = True '允许拖动行
lvw
.AllowDrop = True '允许接收拖动过来的行

有一个需要特别注意的问题,当需要向ListView大量添加行之前,不能将AllowDrop属性设置为True,可以在添加行之后,再将 AllowDrop属性设置为True,否则会大大影响添加行的效率;有兴趣的话,分别比较以下两段代码的效率。

1、AllowDrop设置为True后,再添加行,效率低:

Dim dt As Date = Date.Now()
Dim
lvw As WinForm.ListView = e.Form.Controls("ListView2")
lvw
.View = ViewMode.SmallIcon
lvw
.AllowDrop = True
lvw
.AllowDrag = True
lvw
.StopRedraw
For
i As Integer = 1 To 1000
    Dim vr As WinForm.ListViewRow = lvw.Rows.Add()
    vr.Name = i
    vr.Text =
"
项目"  & i
Next

lvw
.ResumeRedraw

2、先添加行,再将AllowDrop属性设置为True,效率高:

Dim dt As Date = Date.Now()
Dim
lvw As WinForm.ListView = e.Form.Controls("ListView2")
lvw
.View = ViewMode.SmallIcon
lvw
.StopRedraw
For
i As Integer = 1 To 1000
    Dim vr As WinForm.ListViewRow = lvw.Rows.Add()
   
vr.Name = i
    vr.Text = "项目"  &
i

Next

lvw
.AllowDrop = True
lvw
.AllowDrag = True
lvw
.ResumeRedraw

当然有大量数据需要显示的时候,还是建议用虚拟模式,比较快捷。

 


本页地址:http://www.foxtable.com/webhelp/topics/2840.htm