❔ How to convert from one type to a different type
I am still a week or so old in C# so still learning :). Please be patient if I misunderstand.
I am using the Autodesk Revit API to create an Addin.
I have a windows form with a list and will update colour if element is selected.
I need to convert from
string
to a new type called ElementId
as my method after this requires this. How do I do this? I used this as ref: https://stackoverflow.com/questions/60405465/cannot-implicitly-convert-type-string-to-autodesk-revit-bd-displayunittype
The list is generated from ElementIds converted to string. I want to use whatever is currently selected, convert from string to ElementId, then override the colour to make it clear to the user which is is selected currently.5 Replies
i have no clue about Autodesk Revit, but
ElementId
doesn't seem to be an enum
i'd guess that selectionList.SelectedItem
already is a ElementId
. you would just have to cast it like this: ElementId curItemId = (ElementId)selectionList.SelectedItem
SelectedItem
is defined as object
so you can put any type in there, with the downside that you have to cast it into the right type when you get the item out again 😉Ah didn't know you could do it like that, WIll test it out!
Perfect @icebear thanks alot!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.