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: 

Level data to datagridview

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
vanlion
693 Views, 2 Replies

Level data to datagridview

Hello,

 

I have a question how to get data to a winfrom that is using a Datagridview.

 

I have the following code that is working to collect the Level info, see below:

 

But how can you simply display the collected info to the Datagridview? because it's not a public value that you can use with

Datagridview.DataSource= levelDataSourceRow

 

Thanks!

 

namespace Getlevel
{
    [Transaction(TransactionMode.Manual)]
    public class LevelInfo : IExternalCommand
    {

        public Result Execute
               (ExternalCommandData commandData,
                ref string message,
                ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            Transaction documentTransaction = new Transaction(doc, "Document");
            documentTransaction.Start();
            {
                try
                {
                    

                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    ICollection<Element> collection = collector.OfClass(typeof(Level)).ToElements();
                    foreach (Element e in collection)
                    {
                        Level level = e as Level;
                        LevelData levelDataSourceRow = new LevelData();

                        levelDataSourceRow.LevelID = level.Id.IntegerValue;
                        levelDataSourceRow.Naam = level.Name;
                        levelDataSourceRow.Hoogte = level.Elevation;
                    }


                    using (InfoLevel displayform = new InfoLevel(commandData))
                    {
                        displayform.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    documentTransaction.RollBack();
                    return Autodesk.Revit.UI.Result.Failed;
                }
                documentTransaction.Commit();
                return Autodesk.Revit.UI.Result.Succeeded;
            }
                        
        }
    }
}
2 REPLIES 2
Message 2 of 3
jeremytammik
in reply to: vanlion

Put the data into an intermediary container that you can use as a data source.

 

Here is a sample that does just that:

 

http://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3
vanlion
in reply to: jeremytammik

Thanks for the answer a very helpfull example you sent. I also tried the method from the level property sample. This was also doing the job for me!

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

Post to forums  

Forma Design Contest


Rail Community