DataGridView.GetClipboardContent メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim returnValue As DataObject returnValue = instance.GetClipboardContent
選択されたセルの内容を表す DataObject。


このメソッドは、選択したセルによって定義された領域を表すデータを取得します。この領域は、選択されたセルをすべて含む最小の四角形です。この領域で選択されている各セルの値を取得するには、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."; } } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridView.ClipboardCopyMode
DataGridViewClipboardCopyMode
DataFormats クラス
その他の技術情報
DataGridView コントロール (Windows フォーム)
Weblioに収録されているすべての辞書からDataGridView.GetClipboardContent メソッドを検索する場合は、下記のリンクをクリックしてください。

- DataGridView.GetClipboardContent メソッドのページへのリンク