Editor for Custom Items RichTextBox

4 posts, 0 answers
  1. im
    im avatar
    27 posts
    Member since:
    Mar 2012

    Posted 04 Feb 2013 Link to this post

    I have a Listview and created a custom item using the VisualItem, like in the demo's and in the form. It displays multiple lines of text as HTML, and each item is data-bound, to a List<String>. My question is, how can I have an editor for this, which will take (either auto, or programaticaly),  the list of strings so I can edit them in a MultiLIneText Box, or even better a RadRichTextBox Editor?
  2. Anton
    Admin
    Anton avatar
    167 posts

    Posted 07 Feb 2013 Link to this post

    Hello Derek,

    You should follow these steps in order to use RadRichTextBox as an editor inside RadListView:

    1. Create your custom editor that inherits from BaseInputEditor class:

    public class RichTextEditor : BaseInputEditor
    {
        public override object Value
        {
            get
            {
                var editor = ((RadHostItem)EditorElement).HostedControl as RadRichTextBox;
                var htmlFormatter = new TxtFormatProvider();
                string stringValue = htmlFormatter.Export(editor.Document);
                List<string> value = stringValue.Split(new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries).ToList();
                return value;
            }
            set
            {
                string stringValue = String.Concat(((List<string>)value).Select(x => x + "\r\n"));
                var editor = ((RadHostItem)EditorElement).HostedControl as RadRichTextBox;
                var htmlFormatter = new TxtFormatProvider();
                editor.Document = htmlFormatter.Import(Convert.ToString(stringValue));
            }
        }
     
        public override void BeginEdit()
        {
            base.BeginEdit();
        }
     
        public override bool EndEdit()
        {
            return base.EndEdit();
        }
     
        protected override RadElement CreateEditorElement()
        {
            RadHostItem editor = new RadHostItem(new RadRichTextBox());
            editor.RouteMessages = false;
     
            return editor;
        }
     
        public override Type DataType
        {
            get { return typeof(string); }
        }
    }

    2. Attach the editor by handling the EditorRequered event:

               this.radListView1.EditorRequired += new ListViewItemEditorRequiredEventHandler(radListView1_EditorRequired);
    ................................................
     
           void radListView1_EditorRequired(object sender, ListViewItemEditorRequiredEventArgs e)
           {
               e.Editor = new RichTextEditor();
           }

    Attached is a demo project that demonstrates the code above.

    If you have further questions, feel free to write back.

    Greetings,
    Anton
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. im
    im avatar
    27 posts
    Member since:
    Mar 2012

    Posted 01 Mar 2013 Link to this post

    This worked out well for me, unfortunately now, (after upgrading) When I go into edit mode and if I select some text, my app crashes with the folowing error...

    "Could not load file or assembly 'Telerik.WinControls, Version=2012.3.1211.40, Culture=neutral, PublicKeyToken=5bb2a467cbec794e' or one of its dependencies. The system cannot find the file specified.":"Telerik.WinControls, Version=2012.3.1211.40, Culture=neutral, PublicKeyToken=5bb2a467cbec794e"}

    Which the 2012 controls arent on my machine anymore, as I have all the latest ones, so Im not sure why its trying to load a 2012 version when 2013 is already loaded and running. I went through the references, and dont see anything from 2012. 

    The example app runs just fine, and my code is the same. 

    Any ideas?
    UPDATE:

    I fixed the issue be deleting all temporary files, obj and bin directories. Works as expected again. Left over older file.
  5. Anton
    Admin
    Anton avatar
    167 posts

    Posted 05 Mar 2013 Link to this post

    Hello Derek,

    Thank you for writing back.

    I am glad to hear that everything is working as expected.

    You can resolve issues like by using the Rebuild command of your solution. This will Clean and then Build the solution from scratch, so the files in the bin and obj folders will be recreated.

    If you have further questions, feel free to write back.

    All the best,
    Anton
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
Back to Top