pasting into a DataGrid

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
allffAsked:
Who is Participating?
 
arif_eqbalCommented:
There are quite a few ways you can achieve what you want, I will list them in order of preferences...

1.
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
then

       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

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

3.
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.