本文向大家展示了listview控件在report视图下任何列头的双向排序技巧,源代码如下 option explicit private sub form_load() dim i as integer end sub private sub listview1_columnclick(byval columnheader as mscomctllib.columnheader) 完
dim itemx as listitem
listview1.view = lvwreport
with listview1.columnheaders
.add , , "编号", 600, lvwcolumnleft
for i = 1 to 2
.add , , "内容项" & i, 1000, lvwcolumnright
next
end with
with listview1.listitems
for i = 1 to 10
set itemx = .add
itemx.subitems(1) = i
itemx.subitems(2) = chr(64 + i)
itemx.subitems(3) = format(dateadd("m", i, date), "yyyy-mm-dd")
next
end with
with listview1
if (columnheader.index - 1) = .sortkey then
.sortorder = (.sortorder + 1) mod 2
else
.sorted = false
.sortorder = 0
.sortkey = columnheader.index - 1
.sorted = true
end if
end with
end sub