オペレーションモードを行選択モード(RowMode)にするとセルの値をクリップボードへコピーできません
対象製品
SPREAD for Windows Forms 5.0J
詳細
クリップボードへコピーの操作が実行されると、現在選択されているセルのテキストを取得しクリップボードへコピーします。オペレーションモードが標準モード(Normal)の場合、マウスやキーボード操作によりアクティブセルを移動した場合も、選択セルも自動的に移動します。一方で、行選択モードは1つのアクティブセルが存在しますが、選択セルは存在しません(RowModeではSelectionCountの値が常にゼロ)。
行選択モードのときにアクティブセルの値をコピーする場合は、セルを編集状態にしてから文字列を選択してコピーする方法か、独自のアクションをCtrl+Cキーに設定する方法が考えられます。
◎サンプルコード(VB)
カスタムアクション
◎サンプルコード(C#)
カスタムアクション
行選択モードのときにアクティブセルの値をコピーする場合は、セルを編集状態にしてから文字列を選択してコピーする方法か、独自のアクションをCtrl+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);
}
}
}
関連情報
- ヘッダ部のコピーだけ有効にし、ヘッダ部への文字の貼り付けを無効にする方法
- クリップボードのデータからペースト先のセル範囲を取得する方法
- クリップボードへのコピー時に非表示の行列を除外する方法
- ペースト時にChangeイベントが発生しません
- 【Tips】セルの値のみのカット&ペーストを実装する方法
キーワード
「クリップボード」
この文書は、以前は次のFAQ IDで公開されていました : 13512