C# Update Combobox when new drawing opens in the same session

C# Update Combobox when new drawing opens in the same session

GrahamB8
Contributor Contributor
1,095 Views
4 Replies
Message 1 of 5

C# Update Combobox when new drawing opens in the same session

GrahamB8
Contributor
Contributor

Hi,

I'm in the middle of developing an application that reads the projectname variable in a drawing and checks the value from the items within a combobox.

This works fine when I start the appliction but If I open a new drawing from within the same session of AutoCAD I cant figure out how to get the item to automatically change.

 

            string currProject = GlobalVariables.currProject;
            comboBox1.SelectedIndex = comboBox1.FindStringExact(currProject);

 

I understand that I need a new method but I dont want to use a button click or other user interaction how do I have the value of the combobox update when the user opens a new drawing or starts a new drawing from the same session of AutoCAD?

 

Thanks

Graham

0 Likes
Accepted solutions (1)
1,096 Views
4 Replies
Replies (4)
Message 2 of 5

SENL1362
Advisor
Advisor
Accepted solution

Graham,

Do you know how to use Events?

The Document Created event might be the one you're looking for, like the pseudo sample below.

You also might use the Document BecameCurrent or Document Activated events in order to set the current ProjectNr equal to the one that belongs to the current drawing

See attached screenshot where the Palette Label contents gets updated when switching Active documents.

 

 

public class AppMgr : IExtensionApplication

{

   void IExtensionApplication.Initialize()

   {

        Application.DocumentManager.DocumentCreated += DM_DocumentCreated;

 

 

...

void _bacAcadDocs_DocumentCreated(object sender, DocumentCollectionEventArgs e)

{

     //if Combo is visible

     //    Populate youre Combo

 

Message 3 of 5

_gile
Consultant
Consultant

Hi,

 

What about handling DocumentCollection.DocumentActivated event.

 

Edit: @SENL1362 replied while I was typing.

I think DocumentActivated is a better way because it fires both when a new document is created and when the user switch from an opened document to another one.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 5

SENL1362
Advisor
Advisor
Agree, that's why my reference count for the Created Event==0 🙂
0 Likes
Message 5 of 5

GrahamB8
Contributor
Contributor

Yes that looks to be exactly what I need to learn, thanks a lot for your replies guys!

 

0 Likes