© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
5 replies
Curious

❔ 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.
            //ElementId is type
            //selectionList.SelectedItem is a list of string vals and then get current item. Without ToString() its an object.
            string curItem = selectionList.SelectedItem.ToString();
            ElementId curItemId = (ElementId)Enum.Parse(typeof(ElementId), curItem);
            //curItemId error: type provided must be Enum. Parameter Name: Enum Type.

            Autodesk.Revit.DB.Color overrideColor = new Autodesk.Revit.DB.Color(52, 235, 85);
            updateSequenceInOrderedSelect.OverrideColour(uiapp, curItemId, overrideColor, false);  
            //ElementId is type
            //selectionList.SelectedItem is a list of string vals and then get current item. Without ToString() its an object.
            string curItem = selectionList.SelectedItem.ToString();
            ElementId curItemId = (ElementId)Enum.Parse(typeof(ElementId), curItem);
            //curItemId error: type provided must be Enum. Parameter Name: Enum Type.

            Autodesk.Revit.DB.Color overrideColor = new Autodesk.Revit.DB.Color(52, 235, 85);
            updateSequenceInOrderedSelect.OverrideColour(uiapp, curItemId, overrideColor, false);  

I need to convert from
string
string
to a new type called
ElementId
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.
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

cannot convert from 'TypeA' to 'TypeB' with generics
C#CC# / help
2y ago
✅ Convert from string to Type?
C#CC# / help
3y ago
Retrive TypeDeclarationSyntax from a referenced type
C#CC# / help
4y ago
✅ Cannot convert from anonymous type
C#CC# / help
4y ago