Access the name property of RadButtonElement

7 posts, 1 answers
  1. Par
    Par avatar
    11 posts
    Member since:
    Feb 2008

    Posted 21 Feb 2008 Link to this post

    Hi,

    I have a RibbonBar in my application which contains different RadtabStrip with Chunks and RadButtonElements inside chunks. Now, the problem I am facing is that I need to get through each RadButtonElement on runtime and disable appropriate RadButtonElements according to the condition. The only unique way to identify radbuttonelement is through its name. I am using recursive algorithm to check each element 1 by 1... I tried using 'subelement.Name'  property to identify the control but its showing me empty string for all the control names. can anyone help me out with this? I would highly appreciate any help possible.

    Thanks

    Par
  2. Par
    Par avatar
    11 posts
    Member since:
    Feb 2008

    Posted 22 Feb 2008 Link to this post

    Here is the sample code if it helps

    if

    (controlList.Contains(((Telerik.WinControls.UI.RadButtonElement)subelement).Name))

    {
                

    MessageBox.Show(((Telerik.WinControls.UI.RadButtonElement)subelement).Name);

                if (bool.Parse(controlList[((Telerik.WinControls.UI.RadButtonElement)subelement).Name].ToString()))

                subelement.Enabled =

    false;

                else

                    subelement.Visibility = Telerik.WinControls.

    ElementVisibility.Hidden;

    }

    what this code does it that is checks element's name in Hashtable if it is there then it disables or hides the buttonelemt but subelement.Name always appears as "" for all of the button element. However, I have assigned unique name to each buttonelement.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 22 Feb 2008 Link to this post

    Hello Par,

    The reason which causes the Name property to return an empty string is that RadButtonElement does not serialize the Name property value in the designer. The Name value that is set is only for its instance name. So you can identify a button by its unique instance name. Please refer to the following snippet:
     
     
    if (condition)  
    {  
        this.radButtonElement1.Enabled = false;  
        this.radButtonElement2.Enabled = false;  
        this.radButtonElement5.Enabled = false;  

    Serializing the Name property in the designer will be addressed for one of our future releases.

    What I can notice from your last post is that you are using Enabled and Visibily properties, but I want to warn you that they are not contrary to each other. This means that when you first set the Visibility to Hidden and then set Enabled to true, your button will not show. Instead, you should use Enabled = true and Enabled = false.

    One last thing I would recommend is directly accessing RadButtonElements instances like shown in the code snippet above.

    If you need additional assistance, do not hesitate to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Par
    Par avatar
    11 posts
    Member since:
    Feb 2008

    Posted 22 Feb 2008 Link to this post

    Hello Nikolay,

    Thanks for the reply. But, I think I did not explain you properly what I want. As I said in my previous post that I am using recursive algorithm to go through each element in the form to disable or hide element according to the condition. So, I need to identify element on the runtime. I cannot access element as the way you showed it in snippet. To give you clear picture here is a simple example of what I want:

        foreach( Element in Form)
        {
                if(Element.Name == "radBottonElement1")
                    Element.Enabled = false;
        }

    thus, instead of using "this.radBottonElement1.Enabled = false" I need to identify button element first and then disable it. Can you please suggest me what is the best way to do it? Thank you for your help

    Regards,

    Par
  6. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 25 Feb 2008 Link to this post

    Hello Par,

    As I mentioned, RadButtonElement does not currently have its Name value serialized in the designer. The property that you can use with your code snippet is the Text property, although you cannot be sure that this will provide you with unique values.

    Therefore, I would recommend that you adhere to my code snippet - instead of identifying each button through several foreach and if statements, set the necessary properties to the certain controls. 

    Should you have additional questions, do not hesitate to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Par
    Par avatar
    11 posts
    Member since:
    Feb 2008

    Posted 27 Feb 2008 Link to this post

    Hi Nikolay,

    Thanks for the answer. I was just wondering will Tag property of Rad botton work??  or is it not serialized as well??

    Par
  8. Par
    Par avatar
    11 posts
    Member since:
    Feb 2008

    Posted 27 Feb 2008 Link to this post

    I tried using tag property and seems like it is working. Thanks for your help.
Back to Top
UI for WinForms is Visual Studio 2017 Ready