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

How I dispaly checked RadTreeViewItems`name in RadRichTextBox?

1 Answer 101 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
jiang
Top achievements
Rank 1
jiang asked on 23 Dec 2010, 09:48 AM
Like RadTreeView.png.

I want to dispaly like this [Homer;Bart;Maggie;Maude] in RadRichTextBox .

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 24 Dec 2010, 10:14 AM
Hello jiang,

The first solution is to handle the Checked and Unchecked events of RadTreeView like this:
private void AddBeginning()
{
    this.radRichTextBox1.Insert("[");
}
 
private void AddEnding()
{
    DocumentPosition position = new DocumentPosition(this.radRichTextBox1.Document);
    position.MoveToFirstPositionInDocument();
    position.MoveToNext();
    //Delete the last unnecessary ";" symbol if there are more than one names in the list
    if (this.radRichTextBox1.Document.CaretPosition != position)
    {
        this.radRichTextBox1.Delete(true);
    }
    this.radRichTextBox1.Insert("]");
}
 
// A Handler for both the Checked and Unchecked event of RadTreeView
private void radTreeView_CheckChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    RadTreeView treeView = sender as RadTreeView;
    this.radRichTextBox1.Document.Selection.SelectAll();
    AddBeginning();
    foreach (var check in treeView.CheckedItems)
    {
        this.radRichTextBox1.Insert(String.Format("{0};", check.ToString()));
    }
    AddEnding();
}
In this way, on every check/ uncheck, you go through all items.

There is also a more complex solution, which searches for the unchecked item in RadRichTextBox and deletes it, thus preserving the order of the elements. If you are interested, please refer to the attached demo.

Best wishes,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
General Discussions
Asked by
jiang
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or