ArcGIS 10 Addins write to a form

2378
4
05-12-2011 09:26 PM
Highlighted
New Contributor
Hi

I can't figure how to write the output after pressing a button to a form within my project, can anyone help with this?

I tought it ould be as simple as either addressing the dockable window (DocWindow) and then the listbox (lstResults) control but I just can't get it to work.

Any help appreciated.

Stephen
Reply
0 Kudos
4 Replies
Highlighted
New Contributor
Hi Stephen,
I also work on ArcGIS10 Desktop Add-Ins.
If I understand your question correctly, I hope you are looking for a form with a Listbox, which will display the results from the code you have in the Add-In button when you click it.

Try to add an Add-In component(Dockable Window) to your current project where you added your Add-In button.

1.Add>Class>ArcGIS>DesktopAdd-Ins>Add-in Components>Dockable Window, fill the classname, caption etc., fields on the wizard.
2.If you observe the generated code after adding the above class, it has 2 classes one with the name you gave to the class implements 'User Control' and the other class- 'AddinImpl' class implements the 'ESRI.ArcGIS.Desktop.AddIns.DockableWindow'.
The generated code takes care of linking the UserControl to the DockableWindow. ( you can just change the created class' Implementation from UserControl to 'Form' if you like)
3. Now write a Static method to do what ever you want to deal with the form.Listbox.
4. Add the code to call the Dockable window in the Button Add-In's 'OnClick()' method as:
public class ButtonAddIn : Button
{
   IDockableWindow dwForm;
protected override void OnClick()
{
                UID id = new UIDClass();
                id.Value = ThisAddIn.IDs.DockableWindow; // you can see the list of Add-In classes 
                after you write 'IDs.' and select the window you want to display that has the list box.
              
                if (dwForm == null)
                {
                    dwForm = ArcMap.DockableWindowManager.GetDockableWindow(id);
                }
                if (dwForm == null)
                    return;

                //Call the method you wrote it in the Form to display the List box results here:
               
                DockableWindow1.Method1( ); // or  you can directly write the code to display the 
                results in the list box here itself when you change the ListBox1's 'Modifiers' property to 
                'Public' and then write the code as:
               
                DockableWindow1.Listbox1.Items.Add("Resulsts:");

                dwForm.Show(!dwForm.IsVisible()); //To toggle the window on clicking the button
}

}

Hope it helps and if you still have any problems, please let me know.

You can see the sample code in the links below but you may get confused as it has lot of implementations on the project that includes 'Tools', 'Extensions', etc.,,

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Custom_selection...

For the dockable window code:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Custom_selection...

For the Add-In Button code:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Custom_selection...

Good luck!

Hi
I can't figure how to write the output after pressing a button to a form within my project, can anyone help with this?

I tought it ould be as simple as either addressing the dockable window (DocWindow) and then the listbox (lstResults) control but I just can't get it to work.

Any help appreciated.

Stephen
Reply
0 Kudos
Highlighted
New Contributor

Good luck!

Thanks for the help I didn't have the list control set to public so I changed this but I am still getting a null reference when I try to address it.

My code was quite similar to yours (VB.NET) and I now have:

Protected Overrides Sub OnClick()
Dim m As imap
Dim e As IEnumLayer
m = My.ArcMap.Document.FocusMap
e = m.Layers(Nothing, True)
e.Reset()
Dim layer As ILayer
layer = e.Next
Dim dockWindow As ESRI.ArcGIS.Framework.IDockableWindow
Dim dockWinID As UID = New UIDClass()
dockWinID.Value = My.ThisAddIn.IDs.pradDocWin
dockwindow = My.ArcMap.DockableWindowManager.GetDockableWindow(dockWinID)
While Not (layer Is Nothing)
dockWindow.docwinlistbox.items.add(layer.Name)
layer = e.Next
End While
dockWindow.Show(True)
End Sub

The red section holds the problem line with docwinlistbox coming out as a null - the list box is called this on the form - name property and as I mentioned before the Modifiers=Public now..

Thanks

Stephen
Reply
0 Kudos
Highlighted
New Contributor
Thanks for the help I didn't have the list control set to public so I changed this but I am still getting a null reference when I try to address it. 

My code was quite similar to yours (VB.NET) and I now have: 

Protected Overrides Sub OnClick() 
Dim m As imap 
Dim e As IEnumLayer 
m = My.ArcMap.Document.FocusMap 
e = m.Layers(Nothing, True) 
e.Reset() 
Dim layer As ILayer 
layer = e.Next 
Dim dockWindow As ESRI.ArcGIS.Framework.IDockableWindow 
Dim dockWinID As UID = New UIDClass() 
dockWinID.Value = My.ThisAddIn.IDs.pradDocWin 
dockwindow = My.ArcMap.DockableWindowManager.GetDockableWindow(dockWinID) 
While Not (layer Is Nothing) 
   dockWindow.docwinlistbox.items.add(layer.Name)
layer = e.Next 
End While 
dockWindow.Show(True) 
End Sub 

The red section holds the problem line with docwinlistbox coming out as a null - the list box is called this on the form - name property and as I mentioned before the Modifiers=Public now.. 

Thanks 

Stephen


yes, there was an error at that line you wrote.
You should call the docwinlistbox with the Dockablewindow class itself, not with the object on the Dockable window.
For this to work, you need to create a static listbox variable on the dockablewindow class and assign the 'docwinlistbox' to it and then you can call the newly created static listbox variable to add the items.

code in the dockablewindow class:
public partial class pradDocWin: UserControl
{
public static ListBox lb;


public pradDocWin(object hook)
{
InitializeComponent();
this.Hook = hook;
lb = docwinlistbox;

}

}

So now replace that red line in the add-in button's class with the line below:

pradDocWin.lb.items.add(layer.Name)

Actually you need to clear existing list box items before adding the new items when you click the Add-in button to display the results list box on the form. Other wise, when you close the form and try to redisplay the form, the list box will have duplicate entries.

so you should write this code as:
pradDocWin.lb.items.clear( );
pradDocWin.lb.items.add(layer.Name)

hope it should work now!!
Reply
0 Kudos
Highlighted
New Contributor
Thanks Sandhya

It is now coming back to me!  I now have the list box successfully listing the data.  I really tried to make a simple tack so complicated!

Cheers for your help.

Stephen
Reply
0 Kudos