CLR: .Net / Mono / Boo / Otros CLR > VB .NET

 Copiar Y Pegar Filas Completas En Un Datagrid

(1/1)

juanluis:
Hola a todos,

Estoy iniciando un programa nuevo y deseo implementar la Opción de Marcar una fila completa en un datagrid pulsar crtl+C y pegarla con Ctrl+V en una nueva fila.

No lo consigo, como mucho se pega todo el contenido en una celda.

He probado con el codigo de la ayuda de Microsoft Siguiente:


--- Código: Text --- Public Class Form1    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()                Me.TextBox1.Text = Clipboard.GetData(DataFormats.OemText)                 Me.DataGridView1.Rows.Add(Me.TextBox1.Text)            Catch ex As System.Runtime.InteropServices.ExternalException                Me.TextBox1.Text = _                    "The Clipboard could not be accessed. Please try again."            End Try         End If     End SubEnd Class  
Lo he modificado un poco para que inserte una nueva fila al pulsar el botón "PasteButton".

En la instrucción: Clipboard.GetData(DataFormats.OemText) he probado con todos los dataformats posibles y nada  :unsure:

Espero vuestra ayuda  :hola: Gracias.

DENPZ:
Hola no se si sea demasiado tarde para la respuesta. si lo q deseas es copiar a porta papeles el datagr. a ese código solo agrégale
 DataGridView1.SelectAll() con esto te copiara mas q la primera fila.

Navegación

[0] Índice de Mensajes

Ir a la versión completa