Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Waiting until a modeless event is finished within a button event before populating a data grid view with the events data

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
FrankHolidaytoiling
355 Views, 4 Replies

Waiting until a modeless event is finished within a button event before populating a data grid view with the events data

I have the below modeless from button click event that i want to get exterior walls using a rollback transcation, works fine! then i have to double click the button to get the next populate the DGV function to run. Is there any wait i can use to listen for the finish of the event?  

 

private void BtnGetExteriorWalls_MouseClick(object sender, MouseEventArgs e)
{
    foreach (ListViewItem lvi in ListViewLevelPlans.SelectedItems)
    {
         SelectedViews.Add(lvi.Tag as View);
    }


    if (!SelectedViews.Any()) throw new Exception("No Plan Views Selected!");

           //raise the event that populates the list of walls!
           ElevHandler.GetExteriorWallsEvent("GET_EXTERIOR_WALLS", selectedViews);
           ElevEvent.Raise();

 

       //here i add the returned views from a list, to the datagrid view. i have to clikc the button evetn twice.

       PopulateDGVWithWallGroupings();
}

4 REPLIES 4
Message 2 of 5

Your PopulateDGVWithWallGroupings is in the wrong place

 

After you raise the event, it will immediately try and populate the grid i.e. before the event handler is actually called by Revit to do the work.

 

The obvious location to update the DGV is at the end of the code that is raised not the code that raises it.

 

You are using Forms so if the window showing the DGV is on a different thread you may have to use a delegate to update it. In WPF you would use the dispatcher. It might work without either for the API, depends what Revit is doing with its threads for the external event and how you created the window. I can't recall having to take these measures when updating the window externally (from Revit API event handler) in the past but if you do get an exception trying to update the DGV from the handler then that'll be the reason and how to fix it.

Message 3 of 5

Hi RPThomas thought you would answer this one. I have used a delegate once before I will give it a go, I assume the Handler has no wait boolean or something to assist?

 

Message 4 of 5

No that should not be required since it is synchronous i.e. update would inherently occur at right point after task is complete. It is just a case of putting it in the right order.

 

When you step through, you'll see there is a delayed execution to your handler being called because Revit is either busy doing something else or waiting to get the focus back.

 

Message 5 of 5

Hi,

I managed to use the selection(selected index changed) event of a listview, to invoke the external event handler. this seperated the DGV refresh to a seperate button...  PopulateDGVWithWallGroupings(); 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community