copy & paste in visual basic 2005 datagrid

Hi
I

am building a datagridview form in VisualStudio 2005 and I want the

user to be able to copy or paste the content of a cell without needing

to select its text first (as this can become tyresome after a while).

In excell databased tables you're able to copy the cell's content just

by selecting the cell and pressing ctrl + C (not actually selecting the

text inside the cell). Can't seem to do it with my visual studio form.

Thanx for any help

[535 byte] By [xanxa5] at [2007-12-23]
# 1
It seems like the best way to do this would be to handle key strokes on your DataGridview. If the keystroke is CTRL-C then put the text of the selected cell into the clipboard
JaredParsonsMSFT at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Thanks for your answer. I'm not sure, though, what kind of code to apply for key stroke and where to place it.
I've been able so sort out one part of the problem by switchng the clipboardCopyMode property of the Datagridview to 'Enable Without Header Text'. Now I'm able to copy the cell's content by just selecting it and pressing ctrl-C. If I then select another cell and press Ctrl V it doesn't past the data on the cell. It does it only if I first double click on the cell.
xanxa5 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

You can capture the key press by handling the KeyUp event on the DataGridView. Below is some sample code showing how to determine if control-c was pressed.


Private Sub OnGridKeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyUp
If e.KeyCode = Keys.C AndAlso e.Control Then
' Copy the current cell
End If
End Sub

JaredParsonsMSFT at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Hi, i have a similar problem. I cannt seem to copy or paste into my datagrid view. I always have to right click on my mouse to copy or paste. Why?
DaPosh at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
I can't quite tell what your problem is. What are you expecting the user to do in order to paste information into the datagridview?
JaredParsonsMSFT at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...