Vb Copy and paste multiple cells within DataGridView

this only can paste to 1 cells
how to make it can paste to multi cells
Private Sub CustomerDataGridView_KeyDown(sender As Object, e As KeyEventArgs) Handles CustomerDataGridView.KeyDown
        If CustomerDataGridView.RowCount > 0 Then
            If e.Control And (e.KeyCode = Keys.C) Then
                Dim d As DataObject = CustomerDataGridView.GetClipboardContent()
                Clipboard.SetDataObject(d)
                e.Handled = True
            ElseIf (e.Control And e.KeyCode = Keys.V) Then
                PasteUnboundRecords(CustomerDataGridView)
            End If
        End If
    End Sub
Private Sub PasteUnboundRecords(ByVal dgv As DataGridView)
        Try
            Dim rowLines As String() = Clipboard.GetText(TextDataFormat.Text).Split(New String(0) {vbCr & vbLf}, StringSplitOptions.None)
            Dim currentRowIndex As Integer = (If(dgv.CurrentRow IsNot Nothing, dgv.CurrentRow.Index, 0))
            Dim currentColumnIndex As Integer = (If(dgv.CurrentCell IsNot Nothing, dgv.CurrentCell.ColumnIndex, 0))
            Dim currentColumnCount As Integer = dgv.ColumnCount
            For rowLine As Integer = 0 To rowLines.Length - 1
                If rowLine = rowLines.Length - 1 AndAlso String.IsNullOrEmpty(rowLines(rowLine)) Then
                    Exit For
                End If
                Dim columnsData As String() = rowLines(rowLine).Split(New String(0) {vbTab}, StringSplitOptions.None)
                If (currentColumnIndex + columnsData.Length) > dgv.ColumnCount Then
                    For columnCreationCounter As Integer = 0 To ((currentColumnIndex + columnsData.Length) - currentColumnCount) - 1
                        If columnCreationCounter = rowLines.Length - 1 Then
                            Exit For
                        End If
                    Next
                End If
                If dgv.Rows.Count > (currentRowIndex + rowLine) Then
                    For columnsDataIndex As Integer = 0 To columnsData.Length - 1
                        If currentColumnIndex + columnsDataIndex <= dgv.ColumnCount - 1 Then
                            dgv.Rows(currentRowIndex + rowLine).Cells(currentColumnIndex + columnsDataIndex).Value = columnsData(columnsDataIndex)
                        End If
                    Next
                Else
                    Dim pasteCells As String() = New String(dgv.ColumnCount - 1) {}
                    For cellStartCounter As Integer = currentColumnIndex To dgv.ColumnCount - 1
                        If columnsData.Length > (cellStartCounter - currentColumnIndex) Then
                            pasteCells(cellStartCounter) = columnsData(cellStartCounter - currentColumnIndex)
                        End If
                    Next
                End If
            Next
        Catch ex As Exception
        End Try
    End Sub
          

Maybe the below code by
Rbie from below thread.
DataGridView Copy Paste option like Excel
Private Sub DataGridView1_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
If DataGridView1.SelectedCells.Count > 0 Then
DataGridView1.ContextMenuStrip = ContextMenuStrip1
End If
End Sub
Private Sub CutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CutToolStripMenuItem.Click
CopyToClipboard()
For counter As Integer = 0 To DataGridView1.SelectedCells.Count - 1
DataGridView1.SelectedCells(counter).Value = String.Empty
Next
End Sub
Private Sub CopyToClipboard()
Dim dataObj As DataObject = DataGridView1.GetClipboardContent
If Not IsNothing(dataObj) Then
Clipboard.SetDataObject(dataObj)
End If
End Sub
Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CopyToolStripMenuItem.Click
CopyToClipboard()
End Sub
Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PasteToolStripMenuItem.Click
PasteClipboardValue()
End Sub
Private Sub PasteClipboardValue()
If DataGridView1.SelectedCells.Count = 0 Then
MessageBox.Show("No Cell selected", "Paste")
Exit Sub
End If
Dim StartingCell As DataGridViewCell = GetStartingCell(DataGridView1)
Dim rowCount = DataGridView1.SelectedCells.OfType(Of DataGridViewCell)().Select(Function(x) x.RowIndex).Distinct().Count()
Dim cbvalue As Dictionary(Of Integer, Dictionary(Of Integer, String)) = ClipboardValues(Clipboard.GetText)
Dim repeat As Integer = 0
If rowCount > cbvalue.Keys.Count Then
If rowCount Mod cbvalue.Keys.Count <> 0 Then
MessageBox.Show("Selected destination doesn't match")
Exit Sub
Else
repeat = CInt(rowCount / cbvalue.Keys.Count)
End If
End If
Dim irowindex = StartingCell.RowIndex
For x As Integer = 1 To repeat
For Each rowkey As Integer In cbvalue.Keys
Dim icolindex As Integer = StartingCell.ColumnIndex
For Each cellkey As Integer In cbvalue(rowkey).Keys
If icolindex <= DataGridView1.Columns.Count - 1 And irowindex <= DataGridView1.Rows.Count - 1 Then
Dim cell As DataGridViewCell = DataGridView1(icolindex, irowindex)
cell.Value = cbvalue(rowkey)(cellkey)
End If
icolindex += 1
Next
irowindex += 1
Next
Next
End Sub
Private Function GetStartingCell(dgView As DataGridView) As DataGridViewCell
If dgView.SelectedCells.Count = 0 Then Return Nothing
Dim rowIndex As Integer = dgView.Rows.Count - 1
Dim ColIndex As Integer = dgView.Columns.Count - 1
For Each dgvcell As DataGridViewCell In dgView.SelectedCells
If dgvcell.RowIndex < rowIndex Then rowIndex = dgvcell.RowIndex
If dgvcell.ColumnIndex < ColIndex Then ColIndex = dgvcell.ColumnIndex
Next
Return dgView(ColIndex, rowIndex)
End Function
Private Function ClipboardValues(clipboardvalue As String) As Dictionary(Of Integer, Dictionary(Of Integer, String))
Dim lines() As String = clipboardvalue.Split(CChar(Environment.NewLine))
Dim copyValues As Dictionary(Of Integer, Dictionary(Of Integer, String)) = New Dictionary(Of Integer, Dictionary(Of Integer, String))
For i As Integer = 0 To lines.Length - 1
copyValues.Item(i) = New Dictionary(Of Integer, String)
Dim linecontent() As String = lines(i).Split(ChrW(Keys.Tab))
If linecontent.Length = 0 Then
copyValues(i)(0) = String.Empty
Else
For j As Integer = 0 To linecontent.Length - 1
copyValues(i)(j) = linecontent(j)
Next
End If
Next
Return copyValues
End Function
La vida loca

Similar Messages

  • How can I copy and paste table cells from Pages into InDesign with minimum reformating?

    How can I copy and paste table cells from Pages into InDesign with minimum reformating?

    Do you mean you want to retain the formatting from Pages, or retain formatting already applied in ID?

  • Copy and paste multiple text layers DW CC

    I searched around and couldn't find a good solution to an issue I am having.  I am solid with DW but by no means brilliant, so hopefully this doesn't come across as completely ignorant.   Basically, I have a 400 plus page website that I have to do updates on often.. the way the client wanted it designed makes it problematic for updates regardless of my informing him that doing it differently could save us both a lot of problems, but at the same time, the site is actually perfect for what it is due to how it was done and no templating based site out there can do what it does so I am stuck with it for now.  Each of the 400 plus pages has 6 individual text layers that had to be laid out according to the individual photo on each page, very specialized.  My question is, is there a way to copy and paste multiple layers in DW.  Small updates are fine, but larger updates are a nightmare due to the text issue and page numbers, and believe me, I have been up and down and around about how to make it easier.. but, that said, if I could copy all six layers at once and paste all six in the new document, life would be a lot easier on this project.  I also tried linking the layers and sending them, but that doesn't seem to work for some reason.  
    Any thoughts guys?
    Thanks much for your time.

    Thanks Jon, I will give that a try at some point, I am more on the designer end of things but I could manage to find the layers and give that a shot.   I would love to show you the site, but the owner is very security conscious and only allows certain parties to see the site. I don't have any knowledge of background driven sites as web design is more of an extra thing when a client just really wants me involved.  I am fine with the repetitive work.. if what you suggest works, it breaks my job down by 6 times and that would actually be a huge relief.  Though I am over paid and hourly and the client has plenty of money, I just stop enjoying what I am doing with it after a bit to the point that I don't want to do it anymore regardless of the money.  I have thought of subcontracting someone with more experience in the arena that could make it database driven like you are saying, but, it is just such a monster that getting someone else involved (especially with a client that keeps it so close) will be more work than it is worth.  Fortunately, I think there will only be another update or two and then it will be finished as a collection.    The site houses a world renowned textile collection half photo half info about the pieces.. my method thus far has been to keep the photos laid out in Lightroom, where I output the monster site in one of the simple flash sites and then add the text in DW.. I take the new photos and html and connect them to the new site and front thumbnail pages with my original which I have kept adding to over the years.  To a degree it is decently quick and efficient, but when he drops or buys more than 10 pieces, and then needs to change photos, thumbs, and add text to anywhere but the last few pages, it can get into headacheland.   With a major change, it would be faster for me to just reoutput the whole photo based flash site from LR and then copy and paste all six layers on each photo..  but as you know, that has been my issue thus far and what I get for only having my toes into a program. 
    Thanks for your reply..

  • The control click and external mouse right click no longer works when copying and pasting album art within itunes. Ex. Hit get info for one song to paste to the rest, copying the artwork wont work when it used to.

    The control click and external mouse right click no longer works when copying and pasting album art within itunes. Ex. Hit get info for one song to paste to the rest, copying the artwork wont work when it used to.

    Hello there, Teworsham90.
    The following Knowledge Base article reviews the process of adding artwork to content in your iTunes Library:
    iTunes: How to add artwork to songs and videos in your library
    http://support.apple.com/kb/HT1409
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro D.

  • Copy and paste multiple ap divs

    I'm selecting multiple ap divs, copying, and attempting to
    paste to another page. Only the last div in the succession of
    selections is pasting, ie, index page - select div1, div2,
    div3...div10, copy, paste to nextpage.html. Only div 10 appears.
    Thanks for the assistance....
    David Bird

    That is mother nature's way to suggest that you not use so
    many AP Divs.
    I'm afraid it's all you get. What is it you are trying to
    accomplish?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "lusciousleprechaun" <[email protected]>
    wrote in message
    news:fqhs5h$pru$[email protected]..
    >
    >
    > Hi there,
    >
    > Can anyone tell me how to copy and paste multiple AP
    Divs? When I select
    > the
    > AP Divs and do Control C and Control V only the last
    selected AP Div is
    > copied
    > over. This is driving me to drink!
    > Any help would be greated appreciated!
    >
    >

  • Is copying and pasting multiple keyframes disabled?

    I haven't used after effects for a year or so, but I am 100% positive that I was able to copy multiple keyframes or duplicate them just by holding down the alt key and dragging, or by hitting cmd+c and cmd+v. I'm trying to do that now but it copies the actual layers, not the keyframes and I found a plugin here http://aescripts.com/paste-multiple-keyframes/ that lets you copy and paste multiple keyframes .. I really don't understand why adobe would disable such a helpful feature, could anyone let me know if they have the same problem or am I doing something wrong? I'm desperate!
    Thank you

    > I am 100% positive that I was able to copy multiple keyframes or duplicate them just by holding down the alt key and dragging
    That has never been a feature of After Effects.
    > hitting cmd+c and cmd+v
    I just tried copying and pasting multiple keyframes using these commands, and it worked fine for me.
    > I really don't understand why adobe would disable such a helpful feature,
    We changed nothing in this area.

  • Copy and Paste Multiple lines into a single cell

    Folks:
    I need to copy some plain text data into a single cell that has been merged with other cells to provider a larger unit; however, every time I copy and paste my data it gives me an error. In addition, if I paste the data into a single cell, the next line
    of data inserts into the next row.
    I understand that Alt+enter is a quick way to do what I want, but I already have the data typed out, and I do not want to type the data again.
    Example: (If possible I want in one single cell)
    Disks=32
    Total space=1.74TB
    Used space=1.20TB
    Free space=0.54TB
    Thank you!!!

    Is there any way to do this but keep the source formatting? I don't see any "Paste Special" options when you do it this way.
    That is not possible - when you copy/paste this way, you only copy the plain text, not the formatting. You'll have to apply formatting to the cell with pasted lines from scratch.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • How do I copy and paste a cell AND its border?

    In Excel, I can easily select a cell or a range of cells and do a copy and paste.  Both the contents of the cells AND the borders copy to the new area.
    I can't for the life of me figure out how to do this in Numbers.  Help is useless, either in the COPY or the BORDERS area.

    Question already asked and answered several time.
    Numbers is not an Excel clone.
    It behave its own way.
    The efficient resource is not the Help but the User Guide.
    Yvan KOENIG (VALLAURIS, France) vendredi 12 août 2011 09:31:12
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please :
    Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • Problems copying and pasting multiple slides from one captivate to another.

    I have been able to copy and paste several slides into
    another captivate and suddenly this has stopped working. I am using
    the ctrl key to select multiple slides (a set of 3) and the using
    the Edit drop-down to select copy slide. Then, I click on the other
    captivate and click paste slides. It is only bringing 1 slide, the
    first one, and not the 2nd and 3rd... any ideas. I've had another
    set of eyes look over my shoulder... and we're both scratching our
    heads.
    Also, for some reason the text entry boxes are being copied,
    but the failure caption associated with it does not come along. It
    also copied the button but lost the association with the text entry
    box. WTH?

    This might work, this might not. I have copy paste problems
    on a regular basis and all that works for me is closing Captivate
    down and then re open and continue. At worst, a reboot tends to
    solve this glitch in my experience.
    Good Luck

  • How do I copy and paste multiple keyframes?

    I've used previous versions of Final Cut in the past, but primarily have done my editing with Adobe Premiere.  One of the companies I am freelancing for only has Final Cut X on their machines.  I'm a bit confused about keyframes.  Keyframing in the inspector seems severely limited.  I could use some help.
    Basic example:  Say I want to zoom and pan into an image... then have it sit there for 5 seconds... then zoom and pan back to its original location.  I can't figure out how to do this at all with Final Cut X. 
    In Premiere I would accomplish this extremely easily.  
    #1 I'd set my playhead at the location I'd like START my zoom IN/pans and set all my necessary keyframes.
    #2  Then i move my playhead to where I'd like to END my zoom IN/pans, change all my parameters and this sets my necessary keyframes.
    #3  I move my playhead further to where I'd like to START my zoom OUT/pans to where it originally was... and set all my necessary keyframes
    #4 I move my playhead to where I'd like END my zoom OUT/pans to where it originally was... and simply copy and paste my keyframes from step 1...
    The reason why I copy and paste my keyframes from step 1 is because often my parameters are very specific.  I'm not necessary zoomed in 100% at the beginning with my position set exactly where it needs to be.  Say, for instance, I'm working with an image that is zoomed at 75% and perfectly positioned at some random position somewhere in my frame... without the ability to cut and paste keyframes, I'd have to go back to keyframe 1 and write down all the parameters... then go to keyframe 4 and re-enter them.  Massive pain in the butt.
    How is this properly accomplished in Final Cut X?  I can't even see my keyframes on the timeline... every tutorial I've found just says "set keyframe 1 and keyframe 2 in the inspector" and that's incredibly limiting.

    That is kind of a bummer, really.  Maybe I'll need to adjust my workflow, but it seems like it's a MASSIVE drawback of Final Cut X. 
    For example:
    Say I have an image on the screen at with Postion X: 97.3px and Position Y:  -69.3px  with the zoom set to 136.3%... (keyframe 1)
    And say I want to move that image across the screen to Postion X:  32.5px and Position Y: -23.5px with a zoom set to 85.3% ... (keyframe 2)
    Then say I want to let it stay in that position for 10 seconds ... after 10 seconds I'll set more keyframes by clicking the appropriate keyframe buttons and the settings will once again be set for Postion X:  32.5px and Position Y: -23.5px with a zoom set to 85.3% ... (keyframe 3)
    Now say I want it to go back to the original position and zoom.   In premiere I'd just highlight all my keyframes from Keyframe 1 and paste at the new location of the playhead... with Final Cut X, i'll need to go back to Keyframe 1 and literally write down on a piece of paper:  97.3, -69.3, 136.3% ... then go back to Keyframe 4 and type them all out.   This is just a simple example, though.   The more individual parameters I'm setting at specific points... the bigger pain this will be.   Lame. 
    Even with the link you shared... it appears to be completely amature compared to the keyframe editing capabilities of Premiere Pro.  In searching a bit on google to confirm the lack of features, I found someone else complaining:  
    "You cannot expand any parameter that has more than one attribute (like crop or scale or position) - making it useless.
    You cannot add bezier handles to keyframes
    You cannot copy and paste keyframes
    When you copy and paste attributes, you have no choices as to how they will be pasted, etc... it is dismal.
    All in all, it is a step backwards from FCP"
    Personally, I'm a bit surprised... the more I learn about Final Cut X, the more I am starting to like it.  I know a lot of professionals hated it when it initially came out, but I chaulked it up to unfamiliarity with the new software.   For me, this keyframing thing is by far the biggest drawback I've found to yet.

  • Copy and paste multiple texts from Word to Indesign

    Hello!!
    I would like to simplify multiple operations where I need to copy multiple text boxes from a Word doc into multiple boxes in Indesign, and be able to specify the exact location of each box in the Indesign doc. For example, I would like to take 7 text boxes from a Word doc and copy them separately into 7 boxes in the Indesign doc, rather than have to go back and forth into the Word doc. 7 times and pasting each text box one by one.
    See the screenshots
    Thank you in advance,
    Enrico

    That looks a lot like case for Data Merge. It won´t give you any tools for copy/pasting multiple textboxes but with little work, you could make a template where you could drop multiple Items like you have in your screenshot. It won´t work with docs, but if you can convert your stuff to excel, then it would be quite nice solution for you.

  • I can't copy and paste formatted text within the same or between Word and Excel documents

    I run Microsoft Office Professional Plus 2010 (English) (Student Select)
    when I try to copy any formatted text or tables within the same or different Word documents I will always loose the formatting. This is also true if I try to copy formats or formatted tables within Excel or from Excel to Word, see example screenshot:
    When I have a look at my paste options via 'Alt', 'e', 's' or 'Paste special' it only lets me choose between "Unformatted Text" or "Unformatted Unicode Text", see screenshot:
    Here is what I tried already:
    - In the advance options menu all options are on "keep formatting"
    - I uninstalled and reinstalled the entire office suit but keep having the same problem!
    Any ideas?
    Thanks in advance,
    Boston

    I found the solution on another site, superuser.com, so I can't claim the solution as my own, but it worked for me. Kent Ng says: 
    I face the similar issue with Excel 2003. If you have installed Skype-Click-to-Call, just removed it to resolve this issue.

  • Copy and Paste Multiple Layers (or Group)

    I'm trying to copy a selection of multiple layers and then New - Paste to create a new document with the multiple layers.  What's the best way to do this?  Any suggestions?

    dshock wrote:
    Would work perfectly except the Crop doesn't work with Feathered marquee edges...
    Testing it in CS5 shows that it does.
    Crop works with any kind of selection here

  • How to copy and paste an image within adobe pro XI?

    I couldn't figure out how to respond to a question on this, but here is what I found out:
    Select
    Tools | Edit Text & Images
    Select the portion of the image you want to copy
    Ctrl-C (copy)
    Ctrl-V (paste)
    Then drag cursor over the copied portion until you have the 4 arrows -- hold down the left mouse button and drag to where you want to place the image
    Pieces of the image may be selected in the same fashion.  Right clicking on the copied image gives some options for editing the image as a whole, also.e ma
    Hope this helps someone -- took me a while to figure it out -- even though it is simple to do.

    Thread moved from the Adobe Captivate forum.

  • Is it possible to copy and paste a formula without changing the cell references?

    I am trying to paste a formula to a cell adjacent to where it currently is but when I do, the cell references in it change. I am trying to get exactly the same formula in the cell (without re-typing it).

    dedwards96 wrote:
    Just another quick question, is it possible to make a large number of cell references 'absolute'?
    Individual cell references in formulas may have four distinct states: relative, absolute column, absolute row, or absolute column and row. These are set using the popup menu on the reference itself. Click on the reference in the formula and choose one of the four states from the popup menu.
    Once set, you can fill the formula into the rest of a column or row using the Fill Handle (small circle at the lower right of a selected cell). Cell references in the new copies of the formula will remain absolute or adjst to their new position dependent on the setting for each reference. You can also copy and paste the cell (single click to select it, command-C to copy) with the same results.
    You can also copy/paste without changing the formula's cell references if you select the formula (Drag across the formula in the entry bar, copy, press tab to deselect and reconfirm the formula in the original cell) rather than the cell. Pasted into a new cell, the formula will appear as if you typed it in exactly as it was in the original cell—neither absolute references nor relative references will have changed.
    Regards,
    Barry

Maybe you are looking for