0

If I try to use addrange to add this list "builtInCats_List = new List<BuiltInCategory>();," to a list box I get the following error below.

cannot convert from 'System.Collections.Generic.List' to 'System.Windows.Forms.ListBox.ObjectCollection'

How can I populate the listbox on a form with the revit.db list of element category types?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Bimtopian
  • 37
  • 1
  • 5

3 Answers3

1

Looks like addrange needs an array to work. http://msdn.microsoft.com/en-us/library/z018s5az(v=vs.110).aspx

Do you have a collection of Elements that are of a specific builtInCategory? If so, convert your list items to an element array[] and try again. For example, if you looking to add 'Walls' to the listbox using addrange:

 Autodesk.Revit.DB.Element[] Walls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).ToElements().ToArray();
mtumminello
  • 169
  • 1
  • 9
1

Try to convert your List to an Array:

yourListBox.ObjectCollection.AddRange(builtInCats_List.ToArray());
lznt
  • 2,330
  • 2
  • 22
  • 27
0

These lines of code populate the listbox, I found this by skimming through the building coder site. Thanx for your assistance.

lstb1.DataSource = builtInCats_List; lstb1.DisplayMember = "Name";

Bimtopian
  • 37
  • 1
  • 5