DataGridView.GetClipboardContent メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.GetClipboardContent メソッドの意味・解説 

DataGridView.GetClipboardContent メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

Clipboardコピーするために、選択されセル内容を表す書式設定された値を取得します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Overridable Function
 GetClipboardContent As DataObject
Dim instance As DataGridView
Dim returnValue As DataObject

returnValue = instance.GetClipboardContent
public virtual DataObject GetClipboardContent ()
public:
virtual DataObject^ GetClipboardContent ()
public DataObject GetClipboardContent ()
public function GetClipboardContent () : DataObject

戻り値
選択されセル内容を表す DataObject。

例外例外
例外種類条件

NotSupportedException

ClipboardCopyMode が Disable設定されています。

解説解説

このメソッドは、選択したセルによって定義され領域を表すデータ取得します。この領域は、選択されセルをすべて含む最小四角形です。この領域選択されている各セルの値を取得するには、DataGridViewCell.GetClipboardContent メソッド呼び出します。この領域選択されていないセルには、空のプレースホルダ値が使用されます。このメソッドは、クリップボードコピーするために、これらの値を、複数形式を含む DataObject結合しますサポートされているクリップボード形式は、DataFormats.Text、DataFormats.UnicodeText、DataFormats.Html、および DataFormats.CommaSeparatedValue です。

詳細については、Clipboard クラストピック参照してください

継承時の注意 カスタマイズされたクリップボード値を指定するには、このメソッドオーバーライドます。これは、カスタム セル型からの値のコピーサポートする場合などに便利です。

使用例使用例

選択された DataGridView の内容プログラムによってクリップボード追加する方法次のコード例示します次の例は「方法 : ユーザーが、Windows フォーム DataGridView コントロールかクリップボード複数セルコピーできるようにする」で取り上げている例の一部です。

Private Sub Form1_Load(ByVal
 sender As Object, _
    ByVal e As System.EventArgs) Handles
 Me.Load

    ' Initialize the DataGridView control.
    Me.DataGridView1.ColumnCount = 5
    Me.DataGridView1.Rows.Add(New String()
 {"A", "B", "C",
 "D", "E"})
    Me.DataGridView1.Rows.Add(New String()
 {"F", "G", "H",
 "I", "J"})
    Me.DataGridView1.Rows.Add(New String()
 {"K", "L", "M",
 "N", "O"})
    Me.DataGridView1.Rows.Add(New String()
 {"P", "Q", "R",
 "S", "T"})
    Me.DataGridView1.Rows.Add(New String()
 {"U", "V", "W",
 "X", "Y"})
    Me.DataGridView1.AutoResizeColumns()
    Me.DataGridView1.ClipboardCopyMode = _
        DataGridViewClipboardCopyMode.EnableWithoutHeaderText

End Sub

Private Sub PasteButton_Click(ByVal
 sender As Object, _
    ByVal e As System.EventArgs) Handles
 PasteButton.Click

    If Me.DataGridView1.GetCellCount( _
        DataGridViewElementStates.Selected) > 0 Then

        Try

            ' Add the selection to the clipboard.
            Clipboard.SetDataObject( _
                Me.DataGridView1.GetClipboardContent())

            ' Replace the text box contents with the clipboard text.
            Me.TextBox1.Text = Clipboard.GetText()

        Catch ex As System.Runtime.InteropServices.ExternalException
            Me.TextBox1.Text = _
                "The Clipboard could not be accessed. Please try
 again."
        End Try

    End If

End Sub
private void Form1_Load(object sender, System.EventArgs
 e)
{
    // Initialize the DataGridView control.
    this.DataGridView1.ColumnCount = 5;
    this.DataGridView1.Rows.Add(new string[]
 { "A", "B", "C", "D", "E" });
    this.DataGridView1.Rows.Add(new string[]
 { "F", "G", "H", "I", "J" });
    this.DataGridView1.Rows.Add(new string[]
 { "K", "L", "M", "N", "O" });
    this.DataGridView1.Rows.Add(new string[]
 { "P", "Q", "R", "S", "T" });
    this.DataGridView1.Rows.Add(new string[]
 { "U", "V", "W", "X", "Y" });
    this.DataGridView1.AutoResizeColumns();
    this.DataGridView1.ClipboardCopyMode = 
        DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
}

private void PasteButton_Click(object sender,
 System.EventArgs e)
{
    if (this.DataGridView1
        .GetCellCount(DataGridViewElementStates.Selected) > 0)
    {
        try
        {
            // Add the selection to the clipboard.
            Clipboard.SetDataObject(
                this.DataGridView1.GetClipboardContent());
            
            // Replace the text box contents with the clipboard text.
            this.TextBox1.Text = Clipboard.GetText();
        }
        catch (System.Runtime.InteropServices.ExternalException)
        {
            this.TextBox1.Text = 
                "The Clipboard could not be accessed. Please try
 again.";
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridView.ClipboardCopyMode
DataGridViewClipboardCopyMode
DataFormats クラス
その他の技術情報
DataGridView コントロール (Windows フォーム)



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGridView.GetClipboardContent メソッド」の関連用語

DataGridView.GetClipboardContent メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.GetClipboardContent メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS