请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

junlingzhu2002

银牌会员

38

主题

150

帖子

3344

积分

银牌会员

积分
3344

活字格认证

junlingzhu2002
银牌会员   /  发表于:2012-4-17 15:28  /   查看:7553  /  回复:11
因为原有的Paste不能实现我所要得功能,所以自定义了一个。
我还想要追加多行的粘贴,该怎么办
比如
复制了三行DATA,在粘贴时,我选择的行数是三的倍数时,DATA会被复制三遍,可以实现吗

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

11 个回复

倒序浏览
junlingzhu2002
银牌会员   /  发表于:2012-4-17 15:29:00
沙发
改正:我选择的行数是三的三倍时,DATA会被复制三遍
回复 使用道具 举报
robert
金牌服务用户   /  发表于:2012-4-18 15:38:00
板凳
不好意思 MultiRow 控件没有这个功能。
回复 使用道具 举报
junlingzhu2002
银牌会员   /  发表于:2012-4-18 15:49:00
地板
我知道会比较麻烦,你们最近也很忙,
有时间可以帮我看看吗,日语版的帮助给出了下面的方法,
可是会出现错误,怎样改正呀
Public Sub Execute(ByVal target As GrapeCity.Win.MultiRow.GcMultiRow) Implements GrapeCity.Win.MultiRow.IAction.Execute
        Dim temp As String = Clipboard.GetText()
        ' 取得DATA貼り付け
        If Not String.IsNullOrEmpty(temp) Then
            ' 取得したデータの配列変数への設定
            Dim rows As String() = temp.Split(CChar(vbCrLf))
            Dim rCount As Integer = rows.Length
            Dim cCount As Integer = rows(0).Split(CChar(vbTab)).Length
            Dim data As String()() = New String(rCount - 1)() {}
            For i As Integer = 0 To rCount - 1
                data(i) = rows(i).Split(CChar(vbTab))
            Next
            ' 選択領域がCopy元領域の整数倍的判別
            Dim row1 As Integer = target.SelectedCells.Min(Function(c) c.RowIndex)
            Dim row2 As Integer = target.SelectedCells.Max(Function(c) c.RowIndex)
            Dim col1 As Integer = target.SelectedCells.Min(Function(c) c.CellIndex)
            Dim col2 As Integer = target.SelectedCells.Max(Function(c) c.CellIndex)
            Dim isRowMatch As Boolean = (row2 - row1 + 1) Mod rCount = 0
            Dim isColMatch As Boolean = (col2 - col1 + 1) Mod cCount = 0
            If isRowMatch And isColMatch Then
                ' 整数倍になっている場合:ブロック単位の複数回コピーの実行
                For i As Integer = row1 To row2
                    For j As Integer = col1 To col2
                        target.SetValue(i, j, data((i - row1) Mod rCount)((j - col1) Mod cCount))
                    Next
                Next
            Else
                ' 整数倍になっていない場合:通常のペースト操作の実行
                EditingActions.Paste.Execute(target)

            End If
        End If
    End Sub
回复 使用道具 举报
junlingzhu2002
银牌会员   /  发表于:2012-4-18 16:30:00
5#
问题解决了
回复 使用道具 举报
robert
金牌服务用户   /  发表于:2012-4-18 16:33:00
6#
出现了什么错误,我试验了下这个代码貌似没有问题。你发的代码是通过自定义Action来解决这个问题。以下是完整的代码,希望对你有所帮助。
  1. Imports GrapeCity.Win.MultiRow
  2. Public Class Form1
  3.     Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  4.         Me.GcMultiRow1.Template = Template.CreateGridTemplate(10)
  5.         Me.GcMultiRow1.RowCount = 10
  6.         Me.GcMultiRow1.ShortcutKeyManager.Unregister(Keys.V Or Keys.Control)
  7.         Me.GcMultiRow1.ShortcutKeyManager.Register(New MyAction(), Keys.V Or Keys.Control)
  8.     End Sub
  9. End Class
  10. Public Class MyAction
  11.     Implements IAction
  12.     Public Function CanExecute(target As GrapeCity.Win.MultiRow.GcMultiRow) As Boolean Implements GrapeCity.Win.MultiRow.IAction.CanExecute
  13.         Return EditingActions.Paste.CanExecute(target)
  14.     End Function
  15.     Public ReadOnly Property DisplayName As String Implements GrapeCity.Win.MultiRow.IAction.DisplayName
  16.         Get
  17.             Return "CustomPaste"
  18.         End Get
  19.     End Property
  20.     Public Sub Execute(target As GrapeCity.Win.MultiRow.GcMultiRow) Implements GrapeCity.Win.MultiRow.IAction.Execute
  21.         Dim temp As String = Clipboard.GetText()
  22.         ' 取得DATA貼り付け
  23.         If Not String.IsNullOrEmpty(temp) Then
  24.             ' 取得したデータの配列変数への設定
  25.             Dim rows As String() = temp.Split(CChar(vbCrLf))
  26.             Dim rCount As Integer = rows.Length
  27.             Dim cCount As Integer = rows(0).Split(CChar(vbTab)).Length
  28.             Dim data As String()() = New String(rCount - 1)() {}
  29.             For i As Integer = 0 To rCount - 1
  30.                 data(i) = rows(i).Split(CChar(vbTab))
  31.             Next
  32.             ' 選択領域がCopy元領域の整数倍的判別
  33.             Dim row1 As Integer = target.SelectedCells.Min(Function(c) c.RowIndex)
  34.             Dim row2 As Integer = target.SelectedCells.Max(Function(c) c.RowIndex)
  35.             Dim col1 As Integer = target.SelectedCells.Min(Function(c) c.CellIndex)
  36.             Dim col2 As Integer = target.SelectedCells.Max(Function(c) c.CellIndex)
  37.             Dim isRowMatch As Boolean = (row2 - row1 + 1) Mod rCount = 0
  38.             Dim isColMatch As Boolean = (col2 - col1 + 1) Mod cCount = 0
  39.             If isRowMatch And isColMatch Then
  40.                 ' 整数倍になっている場合:ブロック単位の複数回コピーの実行
  41.                 For i As Integer = row1 To row2
  42.                     For j As Integer = col1 To col2
  43.                         target.SetValue(i, j, data((i - row1) Mod rCount)((j - col1) Mod cCount))
  44.                     Next
  45.                 Next
  46.             Else
  47.                 ' 整数倍になっていない場合:通常のペースト操作の実行
  48.                 EditingActions.Paste.Execute(target)
  49.             End If
  50.         End If
  51.     End Sub
  52. End Class
复制代码
回复 使用道具 举报
junlingzhu2002
银牌会员   /  发表于:2012-4-19 09:17:00
7#
代码没有问题,不过
Dim row1 As Integer = target.SelectedCells.Min(Function(c) c.RowIndex)
好像是NET Framework 3.5以降才有的Linq机能,所以我的用不了
:~
回复 使用道具 举报
junlingzhu2002
银牌会员   /  发表于:2012-4-19 09:24:00
8#
顺便问一下,我想把这个自定义Action追加到ContextMenu的粘贴里可以吗
也就是说按下ContextMenu的粘贴时
不用既定的Paste用自定义Action
可以吗
回复 使用道具 举报
robert
金牌服务用户   /  发表于:2012-4-19 09:53:00
9#
可以。在ContextMenu的Item_Click里调用new MyAction().Execute(Me.GcMultiRow1) 就可以了。
回复 使用道具 举报
junlingzhu2002
银牌会员   /  发表于:2012-4-19 12:10:00
10#
谢谢,
可是怎么调用,可以写一下
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部