Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.GiveFeedbackEventArgs'.
This is an Error while loading a page .
Page loading Contains functions for filling combobox and grid .
I can't able to Traise where the error occurs.Please help

Dani AI

Generated

Short, practical diagnosis and fix (adds to and ):

This exception happens when an event handler method expects a more specific EventArgs type than the event actually provides. In other words, a method declared to accept GiveFeedbackEventArgs was wired to an event that raises plain EventArgs (for example Enter/GotFocus). At runtime the CLR attempts to cast the supplied EventArgs into GiveFeedbackEventArgs and throws an InvalidCastException. As found, removing the mismatched GiveFeedback handler removes the crash — but a safer fix is to correct the wiring or the handler signature.

Concrete handler signatures to check and use

' GiveFeedback (drag-and-drop) handler
Private Sub Control_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles Control.GiveFeedback
    ' drag/drop feedback logic
End Sub

' Focus/enter handler
Private Sub TextBox_Enter(sender As Object, e As EventArgs) Handles TextBox.Enter
    ' focus logic
End Sub

Practical troubleshooting steps

  • Search the form and Designer file for any references to "GiveFeedback" (Handles clauses, AddHandler calls or the Designer.vb entries).
  • In the Visual Studio Properties → Events (lightning bolt) for the control, verify the handler assigned to each event is the intended one. Remove or reassign any incorrect entry.
  • If reusing a method across events, ensure the event delegate signatures are compatible. If not, create separate handlers.
  • Rebuild and test; a single miswired handler will reproduce the InvalidCastException at runtime.

Notes: GiveFeedback is for drag-and-drop feedback; focus events use EventArgs. Checking the Designer wiring or using AddHandler/RemoveHandler correctly prevents this class of runtime cast errors.

Recommended Answers

All 3 Replies

You'll have to show some code.

thank u for ur response
I solved the problem.I used GiveFeedback event in place of onfocus event of a textbox.
problem solved by deleting givefeedbackevent

That's good. Please remember to mark this solved, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.