This is a migrated thread and some comments may be shown as answers.

Editor for Custom Items RichTextBox

3 Answers 97 Views
ListView
This is a migrated thread and some comments may be shown as answers.
im
Top achievements
Rank 2
im asked on 04 Feb 2013, 11:22 PM
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?

3 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 07 Feb 2013, 04:42 PM
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.
0
im
Top achievements
Rank 2
answered on 01 Mar 2013, 06:07 PM
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.
0
Anton
Telerik team
answered on 05 Mar 2013, 02:39 PM
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.
Tags
ListView
Asked by
im
Top achievements
Rank 2
Answers by
Anton
Telerik team
im
Top achievements
Rank 2
Share this question
or