出现了什么错误,我试验了下这个代码貌似没有问题。你发的代码是通过自定义Action来解决这个问题。以下是完整的代码,希望对你有所帮助。- Imports GrapeCity.Win.MultiRow
- Public Class Form1
- Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
- Me.GcMultiRow1.Template = Template.CreateGridTemplate(10)
- Me.GcMultiRow1.RowCount = 10
- Me.GcMultiRow1.ShortcutKeyManager.Unregister(Keys.V Or Keys.Control)
- Me.GcMultiRow1.ShortcutKeyManager.Register(New MyAction(), Keys.V Or Keys.Control)
- End Sub
- End Class
- Public Class MyAction
- Implements IAction
- Public Function CanExecute(target As GrapeCity.Win.MultiRow.GcMultiRow) As Boolean Implements GrapeCity.Win.MultiRow.IAction.CanExecute
- Return EditingActions.Paste.CanExecute(target)
- End Function
- Public ReadOnly Property DisplayName As String Implements GrapeCity.Win.MultiRow.IAction.DisplayName
- Get
- Return "CustomPaste"
- End Get
- End Property
- Public Sub Execute(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
- End Class
复制代码 |