找回密码
 立即注册

QQ登录

只需一步,快速开始

qiuzhilv007

中级会员

34

主题

85

帖子

620

积分

中级会员

积分
620

活字格认证微信认证勋章

qiuzhilv007
中级会员   /  发表于:2015-11-19 14:24  /   查看:5483  /  回复:3
在设定Datasource的multirow上,在后几行位置加新行后,重新设定datasource,并把选中单元格,放在加行之前的位置时,光标会跳到0,0位置,再跳到所设定的位置。当行数多时会看到滚动条在上下蹦,同时会闪现第一行。
如何在这个过程中不让滚动条不动和不出现闪现?
以下是测试代码。需要在Form中先拖出一个空的GcMultirow
按enter键会加一行。在最后一行多次按enter键时会出闪现。持续按住enter键效果明显。
在做的项目中因操作复杂,所以每加一行必闪现第一行

  1. Imports GrapeCity.Win.MultiRow
  2. Imports GrapeCity.Win.MultiRow.InputMan

  3. Public Class Form1

  4.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

  5.         Me.Size = New Size(760, 350)

  6.         InitMultirow()
  7.         
  8.     End Sub

  9.     Private Sub GcMultiRow1_KeyDown(sender As Object, e As KeyEventArgs) Handles GcMultiRow1.KeyDown
  10.         If e.KeyCode = Keys.Enter Then
  11.             GcMultiRow1.SuspendLayout()
  12.             Dim tmpDt As DataTable = GcMultiRow1.DataSource.Copy
  13.             Dim dr As DataRow = tmpDt.NewRow
  14.             Dim position As CellPosition = GcMultiRow1.CurrentCellPosition
  15.             dr(0) = position.RowIndex + 1
  16.             dr(1) = "AddRow"
  17.             tmpDt.Rows.InsertAt(dr, position.RowIndex + 1)
  18.             For i As Integer = position.RowIndex To tmpDt.Rows.Count - 1
  19.                 tmpDt.Rows(i)(0) = i + 1
  20.             Next

  21.             GcMultiRow1.DataSource = tmpDt
  22.             GcMultiRow1.CurrentCellPosition = New CellPosition(position.RowIndex + 1, position.CellIndex)
  23.             GcMultiRow1.ResumeLayout()
  24.         End If
  25.     End Sub

  26.     Private Sub InitMultirow()
  27.         GcMultiRow1.AllowUserToAddRows = False
  28.         GcMultiRow1.AllowUserToDeleteRows = False
  29.         GcMultiRow1.Size = New Size(741, 235)
  30.         GcMultiRow1.Location = New Point(1, 5)
  31.         GcMultiRow1.ScrollBars = ScrollBars.Vertical

  32.         Dim tp As Template = New Template()
  33.         tp.Width = GcMultiRow1.Width
  34.         Dim tmpCell As GcTextBoxCell = New GcTextBoxCell
  35.         tmpCell.DataField = "NO"
  36.         tp.Row.Height = tmpCell.Size.Height
  37.         tp.Row.Cells.Add(tmpCell)
  38.         For i As Integer = 1 To 8
  39.             tmpCell = New GcTextBoxCell
  40.             tmpCell.Location = New Point(tmpCell.Size.Width * i, 0)
  41.             tmpCell.DataField = "ID" & i
  42.             tp.Row.Cells.Add(tmpCell)
  43.         Next
  44.         GcMultiRow1.Template = tp

  45.         GcMultiRow1.DataSource = GetDataSource()
  46.         GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter)
  47.     End Sub

  48.     Private Function GetDataSource() As DataTable
  49.         Dim dt1 As DataTable = New DataTable
  50.         Dim col As DataColumn = Nothing
  51.         dt1.Columns.Add("NO")
  52.         dt1.Columns.Add("ID1")
  53.         dt1.Columns.Add("ID2")
  54.         dt1.Columns.Add("ID3")
  55.         dt1.Columns.Add("ID4")
  56.         dt1.Columns.Add("ID5")
  57.         dt1.Columns.Add("ID6")
  58.         dt1.Columns.Add("ID7")
  59.         dt1.Columns.Add("ID8")

  60.         Dim dr As DataRow = Nothing

  61.         For i As Integer = 0 To 15
  62.             dr = dt1.NewRow
  63.             dr(0) = i + 1
  64.             dr(1) = "D100" & i
  65.             dr(2) = "D200" & i
  66.             dr(3) = "D300" & i
  67.             dr(4) = "D400" & i
  68.             dr(5) = "D500" & i
  69.             dr(6) = "D600" & i
  70.             dr(7) = "D700" & i
  71.             dr(8) = "D800" & i
  72.             dt1.Rows.Add(dr)
  73.         Next
  74.         Return dt1
  75.     End Function
  76. End Class
复制代码

3 个回复

倒序浏览
Carl
版主   /  发表于:2015-11-19 15:33:00
沙发
重新设置DataSource属性,会导致MultiRow把当前的所有行删除,然后按照新的数据源添加对应的行。所有行删除之后滚动条自然就回到开始位置了。
所以请尽可能的在当前的DataTable上做修改,不要Copy一个新的DataTable。

评分

参与人数 1满意度 +5 收起 理由
qiuzhilv007 + 5 thanks

查看全部评分

愿 Engine 归于沉寂,Timer 停止运动,Message Queue 不再流淌,Data Source 为我掌握
回复 使用道具 举报
qiuzhilv007
中级会员   /  发表于:2015-11-19 16:56:00
板凳
改为,直接编辑原DataSource的对象了。谢谢回复
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-11-19 17:42:00
地板
回复 3楼qiuzhilv007的帖子

谢谢您的反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部