lisa-marie mueller

lisa-marie mueller

bullet pont

WinForms ComboBox link

February 7, 2019

Laptop with code on screen, film camera, dice, green As I discussed last week, user interfaces can be useful when creating plug-ins. They allow you to show information or allow selections. The post from last week goes into more specific details than I will cover this week.


As a reminder, once you have created your WinForm, you will have a .cs file for your WinFrom and you will have a .cs file for the plug-in within the project. Generally, best practices recommend to have the code for your program in the program’s .cs file and to only have the methods you need for the interface within the WinForms .cs file.

To use a ComboBox, there are two aspects. displaying the data to the user and the final user selection. In the WinForms .cs file we can add the methods that will complete these functions. I will use the user input selection of the View Family as an example.

Our constructor will take in the lists of all the different items we will want to display. In this case, the ViewFamilyType. After we initialize the dialog box, we can display data in the ComboBox. We had named the ComboBox “viewFamilyTypeBox” in its properties menu. Then we set what the ComboBox will display and what the value will be. The reason we need these to be different is that our program will need the ElementId, however, to a user, the ElementId would be meaningless. In order to display the choices in a legible way, we need to show the name as a string. This is why we set the DisplayMember as the ViewFamilyType Name and the ValueMember as the ViewFamilyTypeId.

Then we need a method that allows us to collect the user input. The viewFamilyTypeBox’s selected value is only exposed to the PlaceElevationsDialog class. In order for our program to read the input, we need to provide other classes access to the information. We do this through a public getter property.

We will also want accept and cancel buttons like last week.

execute method

We also have to add a few things to our execute method which is located in the plug-in’s .cs file. We only want this plug-in to run if the selections in the dialog were accepted by the user. We accomplish this by placing it inside an if statement that checks to see if the user pressed the “Okay” button. As you can see in lines 29, 34, 38, and 40 in the snipit below, we call the properties of the dialog box throughout the code and use them in our program’s methods.

Those are the minor adjustments we need to make to add user selections to our Create Elevations Plug-In.


If you want to learn to code and don’t know where to start check out my posts about Steps to Learn to Code [for architects and designers] Part 1 and Part 2.

if you missed it:

Part 1: filtered element collector [c#]

Part 2: finding centroids and considering exceptions

Part 3: ViewFamilyTypeId

Part 4: ViewPlanId and Levels

Part 5: phases & goal #1 complete [includes GitHub link to the release]

Part 6: view tempaltes

Part 7: resizing CropBoxes

Part 8: creating FilledRegions & Goal #2 Complete [includes GitHub link to release]

Part 9: coordinate system utilities

Part 10: rename views & goal #3 complete [includes GitHub link to release]

Revit API Docs