I have not found any solution for this issue. I have a WinForms application that is under development in Visual Studio 2017.
Event handlers are not showing up in the WinForm Designer.
Event handlers are present in the code and work. So this is not an immediate show stopper.
Event handlers were added through the WinForms Designer. I then went to the source code and fleshed out the body of the event handlers.
However, they do not appear in the Windows Form Designer list of events.
Region "Event Handlers"
Private Sub OnCellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles RosterDataGrid.CellValueChanged
Dim changedRow As DataRow = _excelRoster.RosterDataSet.Tables(0).Rows().Item(e.RowIndex)
changedRow.Item(1) = "Updated"
_rosterControl.Updated = _rosterControl.Updated + 1
End Sub
Private Sub OnRowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles RosterDataGrid.RowsAdded
MsgBox("Row Added")
End Sub
#End Region
- But do not show up in the Windows Form Designer. Note that
OnCellValueChanged
that handlesCellValueChanged
does not show up at all in the Events property of the Windows Form Designer.
In the image above, the events for the selected DataGridView
are not present in the Windows Form Designer.
The image above shows the result of the OnCellValueChanged
event handler firing. The Change Type
column is stamped with "Updated" and the Updated
count for Aetna is set to 1.
The image below shows the OnRowsAdded
event firing. There is no entry shown in the Windows Form Designer for the RowsAdded
event for this DataGridView
.
This could be an impediment to other developers who may need to work on this code in the future. Problems like this are indicative that something is fundamentally wrong and could lead to serious problems.
Control Property settings are showing up.
I am using the version 15.9.55 of Visual Studio 2017
Additionally, the "Report a Problem" item in Visual Studio 2017 is not working.
How I am adding event handlers
Below, I am adding an event handler for the RowsRemoved
event of my DataGridView
control.
- In the Windows Form Designer, I locate the
RowsRemoved
event and enterOnRowsRemoved
. - This adds the following code.
Private Sub OnRowsRemoved(sender As Object, e As DataGridViewRowsRemovedEventArgs) Handles RosterDataGrid.RowsRemoved
End Sub
Note that the text OnRowsRemoved
does not exist in the InitializeComponent
method in the Designer
code. No AddHandler
was added to InitializeComponent
.
- When I switch back to the Windows Form Designer, there is no entry for the
RowsRemoved
event.
What I have tried thus far
Repair from the Visual Studio Installer. This does not fix this issue.
"Report a Problem" in Visual Studio 2017 does not work. So I could not Report the Problem.
Cleared the Visual Studio 2017 cache by:
- Close Visual Studio (ensure devenv.exe is not present in the Task Manager)
- Delete the
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\15.0\ComponentModelCache
directory.- Restart Visual Studio.
Note: There is no option to
Clear the Cache
under theMore
button in theVisual Studio Installer
.
Questions
Where does the WinForms designer obtain information on event handlers for controls?
The event handlers are present in code and work.
I do not see any event handlers in the
Designer
code file at all. This is the reason for the question on where designer is looking for handlers.
Notes
- The Windows Form Designer adds a
Friend WithEvents
declaration to theDesigner
source - so individual event handlers are not added to theDesigner
source control. See stackoverflow.com/a/44265658/10024425 as per
Tu deschizi eu inchid in the comments below.