|
| ||||||||||
| Tags: copy, datagrid, pest |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| VB.NET copy from Datagrid & paste to another location?
I want to know if this is possible to copy the data or records from a cell & then paste it somewhere else? What property should be used or I need to code something for this to make it possible? |
|
#2
| |||
| |||
| Re: VB.NET copy from Datagrid & paste to another location?
You have to learn this for what you are asking! http://www.codeproject.com/KB/databa...opyHelper.aspx and http://www.codeproject.com/KB/webfor...rtToExcel.aspx I hope this helps you! |
|
#3
| |||
| |||
| Re: VB.NET copy from Datagrid & paste to another location? Copy datagridview selection to clipboard Code: Private Sub ctxCopyAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ctxCopyAll.Click CopyAllRowsToClipboard() End Sub Private Sub CopyAllRowsToClipboard() Dim intRow As Int32 = 0 Dim drRow As DataGridViewRow = Nothing Dim strClipboard As String = String.Empty For Each drRow In grdBudgetData.Rows drRow.Selected = True grdBudgetData.SelectAll() If intRow = 0 Then grdBudgetData.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText Else grdBudgetData.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText End If If Me.grdBudgetData.GetCellCount(DataGridViewElementStates.Selected) > 0 Then Try ‘ Add the selection to the clipboard. Clipboard.SetDataObject(Me.grdBudgetData.GetClipboardContent()) ‘ Replace the text box contents with the clipboard text. strClipboard = strClipboard + vbCrLf + Clipboard.GetText() Catch ex As System.Runtime.InteropServices.ExternalException Throw New Exception(ex.Message, ex.InnerException) MessageBox.Show(”The Clipboard could not be accessed.”, “Please try again.”, MessageBoxButtons.OK, MessageBoxIcon.Information) End Try End If intRow += 1 Next Clipboard.SetText(strClipboard) End Sub |
|
#4
| |||
| |||
| Re: VB.NET copy from Datagrid & paste to another location?
WindowsForms/Webforms? WindowsForms -> You can trap all keypresses and keyeventcodes right. WebForms -> You can again trap document.onKeyDown function in JavaScript and set the event.keyCode to zero. |
|
#5
| ||||
| ||||
| Re: VB.NET copy from Datagrid & paste to another location?
When you copy data from Excel, the copied data is placed on clipboard as tab delimited data (you can verify this by copy some data some excel and paste in notepad)... So to paste that data to a DataGridView, you'll need to read the data from clipboard as a string, then work on that string to parse out the rows and columns, and then set the datagridview cells accordingly. Now to go the other way, when you copy the data from your DGV, you need to get the values from the selected cells and build a tab delimited string, then place that string on clipboard. That way, you can paste it back to Excel or other DGV's. Code: Public Sub PasteData(ByRef dgv As DataGridView)
Dim tArr() As String
Dim arT() As String
Dim i, ii As Integer
Dim c, cc, r As Integer
tArr = Clipboard.GetText().Split(Environment.NewLine)
r = dgv.SelectedCells(0).RowIndex
c = dgv.SelectedCells(0).ColumnIndex
For i = 0 To tArr.Length - 1
arT = tArr(i).Split(vbTab)
cc = c
For ii = 0 To arT.Length - 1
With dgv.Item(cc, r)
.Value = arT(ii).TrimStart
End With
cc = cc + 1
Next
r = r + 1
Next
End Sub |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "VB.NET copy from Datagrid & paste to another location?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I cannot do Copy and Paste or Paste Special between Excel Workbooks | Acca-OR | Windows Software | 5 | 26-04-2012 04:16 AM |
| Unable to copy and paste in mac | NSA_CIA | Operating Systems | 3 | 17-11-2009 12:46 PM |
| Copy and paste a conditional | Halina | Software Development | 5 | 16-04-2009 11:59 PM |
| How do i Copy and Paste MS-DOS text ? | SamDust | Customize Desktop | 2 | 03-04-2009 01:18 PM |
| Copy Text from One Cell to Another in Microsoft Excel without copy & paste | Computer_Freak | Tips & Tweaks | 0 | 18-03-2009 10:00 PM |