DataSource重新设定时当前选中单元格在0,0位置
在设定Datasource的multirow上,在后几行位置加新行后,重新设定datasource,并把选中单元格,放在加行之前的位置时,光标会跳到0,0位置,再跳到所设定的位置。当行数多时会看到滚动条在上下蹦,同时会闪现第一行。如何在这个过程中不让滚动条不动和不出现闪现?
以下是测试代码。需要在Form中先拖出一个空的GcMultirow
按enter键会加一行。在最后一行多次按enter键时会出闪现。持续按住enter键效果明显。
在做的项目中因操作复杂,所以每加一行必闪现第一行
Imports GrapeCity.Win.MultiRow
Imports GrapeCity.Win.MultiRow.InputMan
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.Size = New Size(760, 350)
InitMultirow()
End Sub
Private Sub GcMultiRow1_KeyDown(sender As Object, e As KeyEventArgs) Handles GcMultiRow1.KeyDown
If e.KeyCode = Keys.Enter Then
GcMultiRow1.SuspendLayout()
Dim tmpDt As DataTable = GcMultiRow1.DataSource.Copy
Dim dr As DataRow = tmpDt.NewRow
Dim position As CellPosition = GcMultiRow1.CurrentCellPosition
dr(0) = position.RowIndex + 1
dr(1) = "AddRow"
tmpDt.Rows.InsertAt(dr, position.RowIndex + 1)
For i As Integer = position.RowIndex To tmpDt.Rows.Count - 1
tmpDt.Rows(i)(0) = i + 1
Next
GcMultiRow1.DataSource = tmpDt
GcMultiRow1.CurrentCellPosition = New CellPosition(position.RowIndex + 1, position.CellIndex)
GcMultiRow1.ResumeLayout()
End If
End Sub
Private Sub InitMultirow()
GcMultiRow1.AllowUserToAddRows = False
GcMultiRow1.AllowUserToDeleteRows = False
GcMultiRow1.Size = New Size(741, 235)
GcMultiRow1.Location = New Point(1, 5)
GcMultiRow1.ScrollBars = ScrollBars.Vertical
Dim tp As Template = New Template()
tp.Width = GcMultiRow1.Width
Dim tmpCell As GcTextBoxCell = New GcTextBoxCell
tmpCell.DataField = "NO"
tp.Row.Height = tmpCell.Size.Height
tp.Row.Cells.Add(tmpCell)
For i As Integer = 1 To 8
tmpCell = New GcTextBoxCell
tmpCell.Location = New Point(tmpCell.Size.Width * i, 0)
tmpCell.DataField = "ID" & i
tp.Row.Cells.Add(tmpCell)
Next
GcMultiRow1.Template = tp
GcMultiRow1.DataSource = GetDataSource()
GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter)
End Sub
Private Function GetDataSource() As DataTable
Dim dt1 As DataTable = New DataTable
Dim col As DataColumn = Nothing
dt1.Columns.Add("NO")
dt1.Columns.Add("ID1")
dt1.Columns.Add("ID2")
dt1.Columns.Add("ID3")
dt1.Columns.Add("ID4")
dt1.Columns.Add("ID5")
dt1.Columns.Add("ID6")
dt1.Columns.Add("ID7")
dt1.Columns.Add("ID8")
Dim dr As DataRow = Nothing
For i As Integer = 0 To 15
dr = dt1.NewRow
dr(0) = i + 1
dr(1) = "D100" & i
dr(2) = "D200" & i
dr(3) = "D300" & i
dr(4) = "D400" & i
dr(5) = "D500" & i
dr(6) = "D600" & i
dr(7) = "D700" & i
dr(8) = "D800" & i
dt1.Rows.Add(dr)
Next
Return dt1
End Function
End Class
重新设置DataSource属性,会导致MultiRow把当前的所有行删除,然后按照新的数据源添加对应的行。所有行删除之后滚动条自然就回到开始位置了。
所以请尽可能的在当前的DataTable上做修改,不要Copy一个新的DataTable。 改为,直接编辑原DataSource的对象了。谢谢回复 回复 3楼qiuzhilv007的帖子
谢谢您的反馈。
页:
[1]