I have a string which consist of code. How to load it into the syntax editor

1 Answer 41 Views
SyntaxEditor
Kobus
Top achievements
Rank 1
Iron
Kobus asked on 05 May 2022, 06:26 PM

            txt_DB_Code.Text = lb.clsGenerator.get_table_code(cboTabels.Text, dtColumns);
            byte[] byteArray = Encoding.ASCII.GetBytes(txt_DB_Code.Text);
            MemoryStream stream = new MemoryStream(byteArray);
            txt_DB_Code_syntax_editor.Document = stream;

 

 

 txt_DB_Code.Text value is :

see attached image

Regards

Kobus

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 06 May 2022, 08:35 AM

Hi Kobus,

Thank you for the provided image.

If you have a string and you want to load it inside the RadSyntaxEditor control, you can assign the TextDocument object to the Document property of the RadSyntaxEditor control. The TextDocument class exposes 3 constructors. One of them accepts string parameters. 

this.radSyntaxEditor1.Document = new TextDocument("My Long String here");

Give this approach a try and let me know if it is working for you.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tim H
Top achievements
Rank 1
commented on 27 May 2022, 05:21 PM | edited

Hi @Dinko this method is not working for me:

No exceptions, but nothing is rendered in the WPF app.

Tim H
Top achievements
Rank 1
commented on 27 May 2022, 05:37 PM

Hello @Dinko -- i just downloaded the SDK samples as well and the simple examples also don't render.  For some context my environment:

Windows 11
VS2022
I do have .NET 7 Preview SDK installed (as well as .NET6)

I am using the NuGet package references.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 31 May 2022, 11:36 AM

Hi, Kobus,

I would like to note that this forum is related to RadSyntaxEditor from the Telerik UI for WinForms suite. SInce you mentioned WPF in the previous replies, feel free to use the appropriate forum for WPF related questions: https://www.telerik.com/forums 

As to the WinForms RadSyntaxEditor, feel free to use the following approach: https://docs.telerik.com/devtools/winforms/controls/syntax-editor/getting-started#opening-a-file 

Our Demo application >> SyntaxEditor >> First look example is also quite useful on this topic.

Tags
SyntaxEditor
Asked by
Kobus
Top achievements
Rank 1
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or