Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi!

I need to get a string containing a specified control full location namespace...

 

Explaining it better, imagine this:

MyProject +-> MyForm1 +-> TabControl1 +-> TabPage1 +-> Button1

 

Giving the Button1 object as a parameter, I need to have a function that can retrieve me:

 

"MyProject.MyForm1.TabControl1.TabPage1.Button1"

 

 

 

My current solution looks like this:

 

   Shared Function GetParentTreeNamespace(ByVal ctrl As Control) As String
       If ctrl Is Nothing Then Return ""

       Dim pForm As Form = ctrl.FindForm
       Dim retval As String = ctrl.Name

       Dim cCtrl As Control = ctrl
       Do While Not cCtrl.Parent Is Nothing
           If cCtrl.Parent Is pForm Then
               retval = pForm.GetType.FullName & "." & retval
           Else
               retval = cCtrl.Parent.Name & "." & retval
           End If
           cCtrl = cCtrl.Parent
       Loop

       Return retval
   End Function

 

I was hoping that there were a solution without loops and stuff...

 

Thanks,

Alex :p

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...