很早时东拼西凑做了一个插入多行的代码,提供参考:
'dim n as integer = e.form.controls("textbox1").text
if currenttable.position < 0 then
CurrentTable.AddNew(9) ‘(注解:这个数字9 可用文本框(第一行的变量n替换),下同)
For i As Integer = 0 To CurrentTable.Rows.Count-1
CurrentTable(i,"ID") = i+1
next
currenttable.position =0
else
dim ii as integer = CurrentTable.Position
dim d as integer = currenttable.current("ID")
dim ia as integer = CurrentTable.rows.count
dim xh as integer = currenttable.current("_identify")
CurrentTable.AddNew(9) ‘(注解:这个数字9 可用文本框(第一行的变量n替换)
for i as integer = ia to CurrentTable.Rows.count-1
if ii =0
currenttable(i,"ID") = d-1 -0.001*(i-ia)
elseif ii+1 = ia
if d - CurrentTable.rows(ii-1)("id") = 1
currenttable(i,"ID") = CurrentTable.rows(ii-1)("id") +0.0001*(i+1-ia)
else
currenttable(i,"ID") = CurrentTable.rows(ii-1)("id") +0.0001*(i+1-ia)*xh/100
end if
else
if d - CurrentTable.rows(ii-1)("id") = 1
currenttable(i,"ID") = CurrentTable.rows(ii-1)("id")+0.0001*(i+1-ia)
else
currenttable(i,"ID") = CurrentTable.rows(ii-1)("id")+0.00001*(i+1-ia)
end if
end if
next
CurrentTable.Sort = "ID"
For i As Integer = 0 To CurrentTable.Rows.Count-1
CurrentTable(i,"ID") = i+1
next
With CurrentTable
Dim r As Integer
r = .FindRow("[_identify] = " & xh & " ", .Position + 1, True )
If r >= 0 Then
.Position = r-9 ‘(注解:这个数字9 可用文本框(第一行的变量n替换)
End If
End With
end if
'很多地方我也解释不清了,但效果很好,速度也很快,最大插入行数为9999行,由代码中0.0001来限定的。