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
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