DataGridView.ClipboardCopyMode プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim value As DataGridViewClipboardCopyMode value = instance.ClipboardCopyMode instance.ClipboardCopyMode = value
public: property DataGridViewClipboardCopyMode ClipboardCopyMode { DataGridViewClipboardCopyMode get (); void set (DataGridViewClipboardCopyMode value); }
/** @property */ public DataGridViewClipboardCopyMode get_ClipboardCopyMode () /** @property */ public void set_ClipboardCopyMode (DataGridViewClipboardCopyMode value)
public function get ClipboardCopyMode () : DataGridViewClipboardCopyMode public function set ClipboardCopyMode (value : DataGridViewClipboardCopyMode)
DataGridViewClipboardCopyMode 値の 1 つ。既定値は EnableWithAutoHeaderText です。


DataGridView コントロールは、選択された各セルのテキスト形式をクリップボードにコピーします。この値は、文字列に変換されたセル値です。イメージ セルの場合は、Description プロパティの値になります。
値は、Text、UnicodeText、Html、および CommaSeparatedValue の形式でクリップボードにコピーされます。これらの形式は、内容をメモ帳、Microsoft Excel、Microsoft Word などのアプリケーションに貼り付ける場合に便利です。
DataGridView コントロールは、選択されたすべてのセルを含む最小の四角形に格納されたセルをコピーします。選択されたセルを含まない行と列は、コピーされたデータには表示されません。残りの行と列で選択されていないセルは、空のプレースホルダによって表されます。コピー モードと選択モードによっては、コピーされた行と列のヘッダー値もコピーされる場合があります。
ユーザーが内容をコピーすると、DataGridView コントロールは DataObject をクリップボードに追加します。このデータ オブジェクトは、GetClipboardContent メソッドから取得されます。プログラムによってデータ オブジェクトをクリップボードに追加する場合、このメソッドを呼び出すことができます。
GetClipboardContent メソッドは、DataGridViewCell.GetClipboardContent メソッドを呼び出して、個別のセルの値を取得します。派生クラスのこれらのメソッドの一方または両方をオーバーライドして、コピーされたセルのレイアウトをカスタマイズするか、追加のデータ形式をサポートできます。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridViewClipboardCopyMode 列挙体
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Enumeration DataGridViewClipboardCopyMode

メンバ名 | 説明 | |
---|---|---|
Disable | クリップボードへのコピーは無効です。 | |
EnableAlwaysIncludeHeaderText | 選択されたセルのテキスト値をクリップボードにコピーできます。選択されたセルを含む行および列のヘッダー テキストも含まれます。 | |
EnableWithAutoHeaderText | 選択されたセルのテキスト値をクリップボードにコピーできます。選択されたセルを含む行または列の行ヘッダーまたは列ヘッダー テキストは、DataGridView.SelectionMode プロパティが RowHeaderSelect または ColumnHeaderSelect に設定されており、1 つ以上のヘッダーが選択されている場合にのみ含まれます。 | |
EnableWithoutHeaderText | 選択されたセルのテキスト値をクリップボードにコピーできます。ヘッダー テキストは含まれません。 |

この列挙体は、ClipboardCopyMode プロパティで使用され、ユーザーが選択されたセルのテキスト値をクリップボードにコピーできるかどうか、および行ヘッダーと列ヘッダーのテキストを含めるかどうかを示します。

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 CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataGridViewClipboardCopyModeのページへのリンク