Get dynamic UserControl tag name VB.NET


Problem: I'm trying to get the tag name of a dynamically created user control through the button inside that created control.screenshot to understand

I have tried the following code to get the tag name:

Private Sub DownloadViewDelClick(sender As Object, e As EventArgs)
    Dim i As Integer = downloadContainer.Controls.Count - 1
    While i >= 0
        If downloadContainer.Controls(i).Tag = sender Then
        End If
        i -= 1
    End While
End Sub

The following code for creating the dynamic controls:

 Sub create_download_list()
    Dim counter As Integer = 0
    Dim downloadview As New videoviewcontrol
    For Each link As String In downloadList
        AddHandler downloadview.btnDel.Click, AddressOf Me.DownloadViewDelClick
        downloadview.Tag = "downloadview" & counter
        downloadview.TextBox1.Text = link
        counter += 1
End Sub

When I run the application and click on the trash can button on any dynamic control, I get the following error:

  Message=Overload resolution failed because no Public '=' can be called with these arguments:
    'Public Shared Operator =(a As String, b As String) As Boolean':
        Argument matching parameter 'b' cannot convert from 'Button' to 'String'.
   at Microsoft.VisualBasic.CompilerServices.OverloadResolution.ResolveOverloadedCall(String MethodName, List`1 Candidates, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
   at Microsoft.VisualBasic.CompilerServices.Operators.ResolveUserDefinedOperator(UserDefinedOperator Op, Object[] Arguments, Boolean ReportErrors)
   at Microsoft.VisualBasic.CompilerServices.Operators.InvokeObjectUserDefinedOperator(UserDefinedOperator Op, Object[] Arguments)
   at Microsoft.VisualBasic.CompilerServices.Operators.InvokeUserDefinedOperator(UserDefinedOperator Op, Object[] Arguments)
   at Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(Object Left, Object Right, Boolean TextCompare)
   at Bhavesh_YouTube_Downloader.mainWindow.DownloadViewDelClick(Object sender, EventArgs e) in C:\Users\TP043287\source\repos\Bhavesh YouTube Downloader\Bhavesh YouTube Downloader\mainWindow.vb:line 28
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at Bhavesh_YouTube_Downloader.My.MyApplication.Main(String[] Args) in :line 81

The following is the $exception value in 'locals' tab in the output trace window:

+       $exception  {"Overload resolution failed because no Public '=' can be called with these arguments:" & vbCrLf & "    'Public Shared Operator =(a As String, b As String) As Boolean':" & vbCrLf & "        Argument matching parameter 'b' cannot convert from 'Button' to 'String'."}   System.InvalidCastException

I tried to understand this issue but the exceptions value above reads the cannot convert button 'b' to string and I don't have any button named 'b' anywhere. I would appreciate a solution. Sorry for the noob question.. Thank you!

asked on Stack Overflow Jun 2, 2018 by SimpleCoder

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0