如何在VB.NET中的datagrid中使用快捷键 [英] How do I use shortcut key in datagrid in VB.NET
问题描述
Hello Everyone,我是VB.net的新手。暂时不知道OOPS概念。
我有一个有3列的网格,我想在按某个特定键时将相同列的前一行数据粘贴到当前单元格上(例如: - F1)
参见网格
在Above网格中,第一行marks列的值为Test,当我按F1(第二行中的光标)时,我想将Test粘贴到第二行('marks'列单元格)
实施原因因为我需要在网格行上粘贴重复的相同数据
我尝试下面的代码工作,但我不确定哪个是正确的方式
我复制了
Hello Everyone, I am very new to VB.net & don't know OOPS Concept Clearly.
I have a grid that has 3 columns, I want to Paste same column's previous row data on current cell when pressing some specific key(for ex:- F1)
See Grid Here
In the Above grid, First row "marks" column has value "Test", When I pressing F1(cursor in second row) I want to Paste "Test" to the second row('marks' column cell)
Reason to Implement because I need to Paste repeated same data on grid row
I tried below code its working but I am not sure which is right way
I copied
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
来自 Stackoverflow
请解释上面的功能(保护和覆盖的含义及其参数),我正在使用正确或错误的单元格点击事件
我声明
From Stackoverflow
Please Explain above function(meaning of protected and override and its arguments) and I am using cell click event which is right or wrong
I Declared
Dim keyData, msg
但它显示警告消息
But It shows warning message
"Variable 'msg' passed by reference before it has assigned a value. A null reference exception could result at run time"
和
and
"variable 'keydata' is used before it has assigned a value. A null reference exception could result at run time"
我尝试过:
What I have tried:
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim keyData, msg
Select Case DataGridView1.CurrentCell.ColumnIndex
Case gcol.marks
ProcessCmdKey(msg, keyData)
End Select
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
Select Case keyData
Case Keys.F1
Select Case Me.DataGridView1.CurrentCell.ColumnIndex
Case gcol.marks
Dim row = Me.DataGridView1.CurrentCell.RowIndex
With Me.DataGridView1
Dim tobepaste = .Item(gcol.marks, row - 1).Value
.CurrentCell.Value = tobepaste
End With
End Select
Return True
End Select
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
推荐答案
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
覆盖默认功能
System.Windows.Forms.Form
覆盖此函数意味着Form可以响应KeyPress事件
只需在此之后使用任何键组合来操作与Form相关的数据
It overrides Default Function
System.Windows.Forms.Form
overriding this function means Form can respond on KeyPress Event
simply you can use after this any key combinations to manipulate data which is associated with Form
这篇关于如何在VB.NET中的datagrid中使用快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!