In order to make my program more elegant and better organized in concrete case I would like to change DataGridView1variable with referenced variable on top of my Form1 class
Private aDgv As DataGridView
And assign value in Form1_Load
aDgv = DataGridView1
After that I can use aDgv variable across that Form.
Except in such case:
Private Sub aDgv_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles aDgv.KeyDown
aDgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
'etc...
End Sub
Where I get an error:
Handles clause requires a
WithEventsvariable defined in the containing type or one of its base types.
AndaDgvvariable afterHandlesclause is blue underlined.
What to do to get rid of error and get Handles aDgv.SomeEvent to work?
Of course, with referenced aDgv instead of original control name DataGridView1.
The minimal answer is to add
WithEventstoaDgv: