オペレーションモードを行選択モード(RowMode)にするとセルの値をクリップボードへコピーできません
対象製品
SPREAD for Windows Forms 7.0J
詳細
行選択モード(OperationMode.RowMode)では、デフォルトで[Ctrl + C]キーおよび[Ctrl + V]キーに対するコピーおよび貼り付け処理を行う入力マップが設定されていません。行選択モードのときにアクティブセルの値をコピーする場合は、セルを編集状態にしてから文字列を選択してコピーする方法か、独自のアクションをCtrl+Cキーに設定する方法が考えられます。
◎サンプルコード(VB)
カスタムアクション
◎サンプルコード(C#)
カスタムアクション
◎サンプルコード(VB)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.OperationMode = FarPoint.Win.Spread.OperationMode.RowMode
' アクションをマッピングします
Dim am As FarPoint.Win.Spread.ActionMap = FpSpread1.GetActionMap()
am.Put("CustomCopyAction", New CustomCopyAction())
' 作成したサブクラスをマッピングします
Dim im As FarPoint.Win.Spread.InputMap = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)
im.Put(New FarPoint.Win.Spread.Keystroke(Keys.C, Keys.Control), "CustomCopyAction")
End Sub
FpSpread1.ActiveSheet.OperationMode = FarPoint.Win.Spread.OperationMode.RowMode
' アクションをマッピングします
Dim am As FarPoint.Win.Spread.ActionMap = FpSpread1.GetActionMap()
am.Put("CustomCopyAction", New CustomCopyAction())
' 作成したサブクラスをマッピングします
Dim im As FarPoint.Win.Spread.InputMap = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)
im.Put(New FarPoint.Win.Spread.Keystroke(Keys.C, Keys.Control), "CustomCopyAction")
End Sub
カスタムアクション
Public Class CustomCopyAction
Inherits FarPoint.Win.Spread.Action
Public Overrides Sub PerformAction(ByVal sender As Object)
If TypeOf sender Is FarPoint.Win.Spread.SpreadView Then
' SPREADとSheetの取得
Dim spread As FarPoint.Win.Spread.SpreadView = CType(sender, FarPoint.Win.Spread.SpreadView)
Dim sheet As FarPoint.Win.Spread.SheetView = spread.Sheets(spread.ActiveSheetIndex)
' クリップボードへ設定
Dim data As String = String.Concat(sheet.ActiveCell.Value)
Clipboard.SetText(data)
End If
End Sub
End Class
Inherits FarPoint.Win.Spread.Action
Public Overrides Sub PerformAction(ByVal sender As Object)
If TypeOf sender Is FarPoint.Win.Spread.SpreadView Then
' SPREADとSheetの取得
Dim spread As FarPoint.Win.Spread.SpreadView = CType(sender, FarPoint.Win.Spread.SpreadView)
Dim sheet As FarPoint.Win.Spread.SheetView = spread.Sheets(spread.ActiveSheetIndex)
' クリップボードへ設定
Dim data As String = String.Concat(sheet.ActiveCell.Value)
Clipboard.SetText(data)
End If
End Sub
End Class
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
fpSpread1.ActiveSheet.OperationMode = FarPoint.Win.Spread.OperationMode.RowMode;
// アクションをマッピングします
FarPoint.Win.Spread.ActionMap am = fpSpread1.GetActionMap();
am.Put("CustomCopyAction", new CustomCopyAction());
// 作成したサブクラスをマッピングします
FarPoint.Win.Spread.InputMap im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.C, Keys.Control), "CustomCopyAction");
}
{
fpSpread1.ActiveSheet.OperationMode = FarPoint.Win.Spread.OperationMode.RowMode;
// アクションをマッピングします
FarPoint.Win.Spread.ActionMap am = fpSpread1.GetActionMap();
am.Put("CustomCopyAction", new CustomCopyAction());
// 作成したサブクラスをマッピングします
FarPoint.Win.Spread.InputMap im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.C, Keys.Control), "CustomCopyAction");
}
カスタムアクション
public class CustomCopyAction : FarPoint.Win.Spread.Action
{
public override void PerformAction(object sender)
{
if (sender is FarPoint.Win.Spread.SpreadView)
{
// SPREADとSheetの取得
FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
// クリップボードへ設定
string data = String.Concat(sheet.ActiveCell.Value);
Clipboard.SetText(data);
}
}
}
{
public override void PerformAction(object sender)
{
if (sender is FarPoint.Win.Spread.SpreadView)
{
// SPREADとSheetの取得
FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
// クリップボードへ設定
string data = String.Concat(sheet.ActiveCell.Value);
Clipboard.SetText(data);
}
}
}
関連情報
- セルの値のみのペースト機能を実装する方法
- 通常モードのセルに対するデータ貼り付け(CopyAndPaste)のタイミングを取得する方法
- コンテキストメニューから[切り取り][コピー][貼り付け]を行うには
- 【Tips】セルの値のみのカット&ペーストを実装する方法
- ペースト時にChangeイベントが発生しません
キーワード
「クリップボード」