Access Textbox from Dockable Window from another class

4191
7
11-04-2010 06:18 AM
KatrinWalz
New Contributor
Hi!
I am trying to put some text in a textbox. This works fine, as long as my method is in the same class as my dockable window.
But now I want my method to be in another class.
I am able to get access to my dockable window
            UID dockWinID = new UIDClass();
            dockWinID.Value = ThisAddIn.IDs.newDockWindow;

            IDockableWindow dockWindow = ArcCatalog.DockableWindowManager.GetDockableWindow(dockWinID);
            dockWindow.Show(true);


Now, I am searching something like
dockWindow.mytextbox.text = "new text";


But this one doesn't work, as my new class doesn't know mytextbox.

Does anyone know how I can access a Textbox from another class?

Thanks!!
0 Kudos
7 Replies
AlexanderGray
Occasional Contributor III
The dockable window has a userdata property.  The way I did it in the past was to define my own custom class that userdata returns.  This class in turn has a reference to the windows custom control that implements IDockable window.  You can then get a reference to the Idockablewindow, get the user data, cast it to your MyCustomDockWindowClass and call the property from there.  Pardon the VB.NET 

Public Class MyCustomDockWindowClass
  Implements IDockableWindowDef

Private m_userData As customUserData
Public Sub OnCreate(ByVal hook As Object) Implements   IDockableWindowDef.OnCreate
    m_application = CType(hook, IApplication)
    m_userData = New customUserData(Me)
end sub

 Public ReadOnly Property UserData() As Object Implements IDockableWindowDef.UserData
    Get
      Return m_userData
    End Get
  End Property

End Class



Public Class customUserData

  Private m_DockableWindow As MyCustomDockWindowClass
  Public Sub New(ByVal DockableWindow As MyCustomDockWindowClass)
    m_DockableWindow = DockableWindow
  End Sub

  Public Property MyText() As string
    Get
      Return mytextbox.text
    End Get
   Set(value as string)
     mytextbox.text = value
   End Set

  End Property

  Public ReadOnly Property DockableWindow() As IPolarisEditorDockableWin
    Get
      Return m_DockableWindow
    End Get
  End Property
End Class


Now you can go one step further by defining interfaces for these classes so they can work from code in a different dll (as long as they have a reference to the first dll)
0 Kudos
KatrinWalz
New Contributor
Thank you very much agray1!
Unfortunatly, I am not used to VB.NET at all.

I tried to get your code converted to c#, but I wasn't succesfull.

Is anybody able to help me to translate the code?
0 Kudos
KatrinWalz
New Contributor
Is there nobody else who can help me?

I am really desperate!
0 Kudos
LesleyBross
New Contributor II
I think this works a little differently if you are using add-ins vs. traditional VB .NET. I am using add-ins and was unable to get the UserData solution to work for me. I found this blog posting from 'Geospatial Scott'. Hopefully it will help. The example is in C#.

http://geospatialscott.blogspot.com/2010/08/how-to-get-arcgis-add-in-dockable.html

Once you have the handle to the UI (form) you should be able to access the textbox. I was able to adapt the solution for my needs and I am working in VB .NET.
0 Kudos
PaulBarter
New Contributor II
Hi Lesley,

Can you please post your vb.net version for ArcGIS10.
I'm having a similar problem and don't feel inclined to rewrite the C version.
Cheers.
0 Kudos
PaulBarter
New Contributor II
For those that are interested, following is the VB.net version.

Add a reference to the UI form inside the autogenerated code of the dockable window:


'''Auto generated code....
Private m_windowUI As DockWindow1

~~~~~~~~~~~~~~~~~~~~~~~~~
'Add this reference here:
        Friend ReadOnly Property UI() As DockWindow1
            Get
                Return m_windowUI
            End Get
        End Property
~~~~~~~~~~~~~~~~~~~~~~~~

To access, say Textbox1 from a click event in a button, the code is:

Dim addinimpl As DockWindow1.AddinImpl = ESRI.ArcGIS.Desktop.AddIns.AddIn.FromID(Of DockWindow1.AddinImpl)(My.ThisAddIn.IDs.DockWindow1)

            Dim window As DockWindow1 = addinimpl.UI
            MsgBox(window.TextBox1.Text)


Hope this helps.
JeffreyHamblin
New Contributor III
Hi!
...
Does anyone know how I can access a Textbox from another class?



Controls in a form class are private to that class. You can edit the access for the control to public in the 'yourform.Designer.cs' source to gain access to its properties from other classes, but the preferred way is to add a public property to your form class that exposes just what you need -- the text property for the control in your case.

For example, in your dockWindow class, add:

public string MyTextBoxText
{
    get { return mytextbox.text; }
    set { mytextbox.text = value; }
}
0 Kudos