This is a migrated thread and some comments may be shown as answers.

cast control to radcarousel

1 Answer 101 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Jordi Borras
Top achievements
Rank 1
Jordi Borras asked on 20 Jun 2010, 09:54 AM
Hi,

I'm getting an error "cannot convert type system.windows.forms.control to telerik.wincontrols.ui.radcarousel" when I try to convert a control to a radcarousel. Basically, this is the code (some code is missing but are irrelevant for this example):

foreach (Control control in listOfControls)
{
    if (c.getType() == button)
        listOfNames = control.Name;

    if(c.getType() == ToolStrip)
    {
        ToolStrip t = (ToolStrip)control;                         //here I have no problem when I try to cast a control to a ToolStrip control
        foreach (ToolStripItem tsi in t.Items) {...}
    }

    if(c.getType() == RadCarousel)
    {
        RadCarousel r = (RadCarousel)control;             //here I get the error
        foreach (RadButtonElement rbe in r.Items) {...}
    }
}


Thanks

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 23 Jun 2010, 07:23 PM
Hello Jordi Borras,

Thank you for writing.

You are not using the safe casting operators of C#. You need to use the "is" and "as" operators in order to safely cast from one type to another. Also, another issue with the code you posted is that you are calling GetType() on a variable named "c" and then casting a different variable named "control". Please review your code and apply the necessary modifications.

Write again if you need further assistance.

All the best,
Victor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Carousel
Asked by
Jordi Borras
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or