pasting into a DataGrid

Posted on 2005-04-06
Last Modified: 2010-04-23
Does anybody have any code or advise on how i can paste into a grid.

Of course i can already paste into one cell at a time but how could i for example:

copy 3 horizontal cells in Excel, lets say cells A1 to C1.

then go to my DataGrid which has rows of data, click into the top left cell, hit Ctrl-V and get the 3 values that i copied from excel and have them paste into the first 3 cells of my Grid.

is this possible at all ???

Any help or advise would be greatly appreciated.

Thank a lot
Question by:allff
    1 Comment
    LVL 19

    Accepted Solution

    There are quite a few ways you can achieve what you want, I will list them in order of preferences...

    Since you have a dataGrid you must be having a DataTable which is used to populate the Grid. For a grid all data related operations should be done on that underlying Table, (your DataTable might be local to a function, you can make it a form level variable so that it can be accessed)
    So say your DataTable that the Grid bounds to is DT

           Dim DR As DataRow
            DR = DT.Rows(2) 'Say its the Second Row you want to manipulate
            DR(0) = A1
            DR(1) = B1
            DR(2) = C1

    this will do what you want, A1/B1/C1 are the variables holding the copied values from the Excel Cells

    DataGrid.Item(1, 1) = "Any Value"  'Put some value in cell 1,1 of the Grid

    Now in case you have used Clipboard to copy data from Excel, you might be forced to Use Ctrl+V, this is not recommended though as this type of programs are not very robust, anyway here goes

            DataGrid.CurrentCell = New DataGridCell(1, 1) 'Set Focus on the Cell
            SendKeys.Send("^(V)")  'Use SendKeys to simulate Paste

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now