积极答复者
一个大家都想解决的datagridview的问题

问题
答案
-
可以通过Win32API 监控剪切板事件 改写逻辑 达到目的,示例代码如下:
Imports System.Runtime.InteropServices Public Class Form1 '剪切板监控指针 Dim ClipboardViewerNext As IntPtr '声明相关Win32API <DllImport("User32.dll", CharSet:=CharSet.Auto)> _ Public Shared Function SetClipboardViewer(hWnd As IntPtr) As IntPtr End Function <DllImport("User32.dll", CharSet:=CharSet.Auto)> _ Public Shared Function ChangeClipboardChain(hWndRemove As IntPtr, hWndNewNext As IntPtr) As Boolean End Function '注册事件 Private Sub RegisterClipboardViewer() ClipboardViewerNext = SetClipboardViewer(Me.Handle) End Sub '注销事件 Private Sub UnregisterClipboardViewer() ChangeClipboardChain(Me.Handle, ClipboardViewerNext) End Sub Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg '当剪切板内容发生变化时 Case &H308 '将当前焦点所在单元格内容复制到剪切板 Clipboard.SetText(DataGridView1.CurrentCell.Value) Exit Select Case Else MyBase.WndProc(m) Exit Select End Select End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load '添加测试数据 DataGridView1.Rows.Add({"aaa", "bbb", "ccc"}) DataGridView1.Rows.Add({"aaa", "bbb", "ccc"}) End Sub Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick RegisterClipboardViewer() End Sub Private Sub DataGridView1_Leave(sender As System.Object, e As System.EventArgs) Handles DataGridView1.Leave UnregisterClipboardViewer() End Sub End Class
算神的博客- 已标记为答案 Liliane Teng 2011年8月3日 11:12
-
试试currentcell属性,应该就能得到这个单元格的值
比如:在selectchange事件里面写
try
dim txt as string=ctype(datax.currentcell.value,string)
clipboard.clear
clipboard.settext (txt)
catch
end try
这样应该行的。
- 已标记为答案 Liliane Teng 2011年8月3日 11:12
全部回复
-
datagrideview的selection mode 设置为:FULL ROW SELECT,readonly设置为:true,clipboardcopymode设置为:enablewithautoheadertext
这个时候的datagridview只要选就只能选中一行,如果想复制这一行中的某一个单元格的内容该如何去做呢?选中后按CTRL+C,粘贴后会发现粘贴的为一样。在选中一样的前提下,如何复制某一个单元格的内容呢,大家有什么好的办法与建议可以讨论下
您好:)
根据我的经验,你只能把Selection Mode设置成CellSelect而并非Row Select。
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处 -
您好:)
根据我的经验,你只能把Selection Mode设置成CellSelect而并非Row Select。
是的,根据我的经验判断貌似不可以。我当时企图使用ClipBoard的GetString方法得到一串行的数据,设法分离给你做出来。但是问题我也不知道怎么截获这个Ctrl+V事件……
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处 -
可以通过Win32API 监控剪切板事件 改写逻辑 达到目的,示例代码如下:
Imports System.Runtime.InteropServices Public Class Form1 '剪切板监控指针 Dim ClipboardViewerNext As IntPtr '声明相关Win32API <DllImport("User32.dll", CharSet:=CharSet.Auto)> _ Public Shared Function SetClipboardViewer(hWnd As IntPtr) As IntPtr End Function <DllImport("User32.dll", CharSet:=CharSet.Auto)> _ Public Shared Function ChangeClipboardChain(hWndRemove As IntPtr, hWndNewNext As IntPtr) As Boolean End Function '注册事件 Private Sub RegisterClipboardViewer() ClipboardViewerNext = SetClipboardViewer(Me.Handle) End Sub '注销事件 Private Sub UnregisterClipboardViewer() ChangeClipboardChain(Me.Handle, ClipboardViewerNext) End Sub Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg '当剪切板内容发生变化时 Case &H308 '将当前焦点所在单元格内容复制到剪切板 Clipboard.SetText(DataGridView1.CurrentCell.Value) Exit Select Case Else MyBase.WndProc(m) Exit Select End Select End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load '添加测试数据 DataGridView1.Rows.Add({"aaa", "bbb", "ccc"}) DataGridView1.Rows.Add({"aaa", "bbb", "ccc"}) End Sub Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick RegisterClipboardViewer() End Sub Private Sub DataGridView1_Leave(sender As System.Object, e As System.EventArgs) Handles DataGridView1.Leave UnregisterClipboardViewer() End Sub End Class
算神的博客- 已标记为答案 Liliane Teng 2011年8月3日 11:12
-
试试currentcell属性,应该就能得到这个单元格的值
比如:在selectchange事件里面写
try
dim txt as string=ctype(datax.currentcell.value,string)
clipboard.clear
clipboard.settext (txt)
catch
end try
这样应该行的。
- 已标记为答案 Liliane Teng 2011年8月3日 11:12