Strange error when I try to assign string to readonly C1TextBox

Posted by: a.koneva on 16 May 2022, 10:34 pm EST

    • Post Options:
    • Link

    Posted 16 May 2022, 10:34 pm EST

    Hi

    I try to assign a string in runtime to Text property of readonly C1TextBox, but I get a strange error: “Cannot assign text to readonly, disabled or hidden C1Input control when its Text property is not detached”.

    Is there a solution for this problem?

    Best regards,

    Anna.

  • Posted 17 May 2022, 2:01 am EST

    Hi Anna,

    The Text property of the C1TextBox shows the Value property in a properly formatted form. To resolve the issue you are facing, you can either use the Value property instead of the Text property, which will automatically set the Text, OR set the TextDetached property of the C1TextBox to true, which will break the above-mentioned relation between the Text and Value property, allowing the Text property to be assigned.

    Kind Regards,

    Kartik

  • Posted 17 May 2022, 10:11 pm EST

    Thank you for your answer, Kartik.

  • Posted 15 June 2024, 6:24 am EST

    While that works, if I have an application with 1,318 labels, is there a quick way to do this for all the labels?

    The default in the designer.vb files is to use .text

    I can do a search and replace to change the New System.Windows.Forms.Label() to

    New C1.Win.C1Input.C1Label()

    But how can I change teh default use of .text

    I want to use Themes, so would like to swap the controls to take advantage of this.

  • Posted 17 June 2024, 3:27 am EST

    Hi Peter,

    create a subclass of C1Label where you set “TextDetached = true”. Also override the “TextDetached” property and declare the new “DefaultValue(true)” attribute - otherwise WinForms designer would always create a setter for this property.

    Then replace all “New System.Windows.Forms.Label” with “New MyCustomLabelSubclass” and you are done.

    Hope this helps

    Wolfgang

  • Posted 17 June 2024, 4:17 am EST

    Thanks.

  • Posted 18 June 2024, 4:05 am EST

    Hi Peter,

    Please refer to the solution provided by @Wolfgang. It is the best way to replace all the MS Labels with C1 Labels. If you encounter any further issues, let us know and we will assist you further.

    P.S. Thanks a lot for your suggestion, @Wolfgang ;-).

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels