DataGridViewClipboardCopyMode Enumeración
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Define constantes que indican si el contenido se copia de un control DataGridView al Portapapeles.
public enum class DataGridViewClipboardCopyMode
public enum DataGridViewClipboardCopyMode
type DataGridViewClipboardCopyMode =
Public Enum DataGridViewClipboardCopyMode
- Herencia
Campos
| Nombre | Valor | Description |
|---|---|---|
| Disable | 0 | La copia en el Portapapeles está deshabilitada. |
| EnableWithAutoHeaderText | 1 | Los valores de texto de las celdas seleccionadas se pueden copiar en el Portapapeles. El texto del encabezado de fila o columna se incluye para las filas o columnas que contienen celdas seleccionadas solo cuando la SelectionMode propiedad está establecida RowHeaderSelect en o ColumnHeaderSelect y al menos se selecciona un encabezado. |
| EnableWithoutHeaderText | 2 | Los valores de texto de las celdas seleccionadas se pueden copiar en el Portapapeles. No se incluye el texto del encabezado. |
| EnableAlwaysIncludeHeaderText | 3 | Los valores de texto de las celdas seleccionadas se pueden copiar en el Portapapeles. El texto del encabezado se incluye para las filas y columnas que contienen celdas seleccionadas. |
Ejemplos
En el ejemplo de código siguiente se muestra cómo habilitar la copia en el DataGridView control . Para obtener el ejemplo completo, vea How to: Enable Users to Copy Multiple Cells to the Clipboard from the Windows Forms DataGridView Control.
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 CopyPasteButton_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.";
}
}
}
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 CopyPasteButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles CopyPasteButton.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
Comentarios
Esta enumeración la usa la ClipboardCopyMode propiedad para indicar si los usuarios pueden copiar los valores de texto de las celdas seleccionadas en el Portapapeles y si se incluye el texto del encabezado de fila y columna.