/
main.go
103 lines (84 loc) · 2.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"time"
"math/rand"
"github.com/ying32/govcl/vcl"
"github.com/ying32/govcl/vcl/types"
)
type TMainFrom struct {
*vcl.TForm
ListView *vcl.TListView
}
type TTempItem struct {
Caption string
Sub1 string
Sub2 string
Sub3 string
Sub4 string
Sub5 string
}
var (
MainFrom *TMainFrom
tempData []TTempItem
)
func main() {
vcl.Application.Initialize()
vcl.Application.CreateForm(&MainFrom)
vcl.Application.Run()
}
func (f *TMainFrom) OnFormCreate(sender vcl.IObject) {
fmt.Println("OnCreate")
f.ScreenCenter()
f.SetDoubleBuffered(true)
f.ListView = vcl.NewListView(f)
f.ListView.SetAlign(types.AlClient)
f.ListView.SetParent(f)
f.ListView.SetViewStyle(types.VsReport)
f.ListView.SetOwnerData(true)
f.ListView.SetGridLines(true)
f.ListView.SetReadOnly(true)
f.ListView.SetRowSelect(true)
f.ListView.SetOnData(f.OnListView1Data)
col := f.ListView.Columns().Add()
col.SetCaption("行号")
col.SetWidth(100)
col = f.ListView.Columns().Add()
col.SetCaption("子项1")
col.SetWidth(100)
col = f.ListView.Columns().Add()
col.SetCaption("子项2")
col.SetWidth(100)
col = f.ListView.Columns().Add()
col.SetCaption("子项3")
col.SetWidth(100)
col = f.ListView.Columns().Add()
col.SetCaption("子项4")
col.SetWidth(100)
col = f.ListView.Columns().Add()
col.SetCaption("子项5")
col.SetWidth(100)
// 产生100w条数据
tempData = make([]TTempItem, 1000000)
t := time.Now().UnixNano()
for i := 0; i < len(tempData); i++ {
tempData[i].Caption = fmt.Sprintf("%d", i+1)
tempData[i].Sub1 = fmt.Sprintf("子项1:%d", rand.Intn(1000000))
tempData[i].Sub2 = fmt.Sprintf("子项2:%d", rand.Intn(1000000))
tempData[i].Sub3 = fmt.Sprintf("子项3:%d", rand.Intn(1000000))
tempData[i].Sub4 = fmt.Sprintf("子项4:%d", rand.Intn(1000000))
tempData[i].Sub5 = fmt.Sprintf("子项5:%d", rand.Intn(1000000))
}
ns := time.Now().UnixNano() - t // 1e-6
fmt.Println("t:", ns, "ns, ", ns/1E6, "ms")
f.ListView.Items().SetCount(int32(len(tempData))) // 必须主动的设置Virtual List的行数
}
func (f *TMainFrom) OnListView1Data(sender vcl.IObject, item *vcl.TListItem) {
data := tempData[int(item.Index())]
item.SetCaption(data.Caption)
item.SubItems().Add(data.Sub1)
item.SubItems().Add(data.Sub2)
item.SubItems().Add(data.Sub3)
item.SubItems().Add(data.Sub4)
item.SubItems().Add(data.Sub5)
}