copy & paste in visual basic 2005 datagrid
Hi
Iam 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]
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.
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