cast control to radcarousel

2 posts, 0 answers
  1. Jordi Borras
    Jordi Borras avatar
    2 posts
    Member since:
    May 2010

    Posted 20 Jun 2010 Link to this post

    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

  2. Victor
    Admin
    Victor avatar
    1176 posts
    Member since:
    Sep 2012

    Posted 23 Jun 2010 Link to this post

    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

Back to Top