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

want to know selected span ID

10 Answers 171 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Faheem
Top achievements
Rank 1
Faheem asked on 05 Jul 2011, 12:35 PM
I want to get selected span ID, i m getting selected span text using
radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.Text;
.But need a method from which i could get selected span ID.

Regards
Faheem Khatri

10 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 05 Jul 2011, 01:08 PM
Hello Faheem Khatri,

Spans do not have an ID property. The closest thing to an ID is the hash code of the Span, which can be obtained like this:

radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.GetHashCode();
If that does not work for you, we would appreciate some details on the goal you wish to accomplish.

Regards,
Iva
the Telerik team
Register for the Q2 2011 What’s New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
0
Faheem
Top achievements
Rank 1
answered on 05 Jul 2011, 01:18 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">
.p_A215EAA9 { margin: 0px 0px 20px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_2792A6B5 { font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 34.6666679382324px;color: #17365D; }
.p_B0B4BECC { margin: 0px 0px 13.3333330154419px 0px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_79B9C72D { font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; }
.s_47B2206B { font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 16px;color: #0000FF;text-decoration: underline; }
.p_52CCE107 { margin: 0px 0px 13.3333330154419px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_15F27AAB { font-family: 'Calibri';font-style: Normal;font-weight: bold;font-size: 26.6666660308838px;color: #365F91; }
.p_D4BD696B { margin: 0px 0px 0px 20px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_1B36B066 { font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;background-color: #FFFF00; }
.s_E6FD2046 { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; }
.p_55DBFD74 { margin: 0px 0px 0px 0px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_7D26D8AB { font-family: 'Calibri';font-style: Normal;font-weight: bold;font-size: 18.6666660308838px;color: #365F91; }
.p_9AE926D3 { margin: 0px 0px 0px 20px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px;background-color: #FFFFFF; }
.p_D9C3C42D { margin: 32px 0px 0px 0px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_361E4FF5 { font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 14.6666669845581px;color: #333333; }
 
<body><p class="p_A215EAA9"><span id = "ab123456" class="s_2792A6B5">RadRichTextBox for Silverlight and WPF</span></p><p class="p_B0B4BECC"><span id = "ab789" class="s_79B9C72D">RadRichTextBox was initially developed in </span></body></html>
see the span id "ab123456" and "ab789"

i want these span id on selection of text using
radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox()
 
radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan

or anything by which i could get the spanid.

here's my code
   private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            radRichTextBox1.Document = ImportDocx();
        }
 
public RadDocument ImportDocx()
        {
            RadDocument document = null;
 
            IDocumentFormatProvider provider = new Telerik.Windows.Documents.FormatProviders.Html.HtmlFormatProvider();
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "HTML|*.html";
            openDialog.Multiselect = false;
            bool? dialogResult = openDialog.ShowDialog();
            if (dialogResult == true)
            {
                FileStream stream = new FileStream(openDialog.FileName.ToString(),FileMode.Open);
                 
                    document = provider.Import(stream);
                 
                 
            }
            return document;
        }
 
private void radRichTextBox1_MouseUp(object sender, MouseButtonEventArgs e)
        {
                        
            string a = radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.Text;
            //i am getting text, need span ID
        }

Thanks for prompt reply

EDIT: i want to display record from database, and i want to save there record ID too.. so if the user select any of the node(text) its correspond ID would be selected.
Regards
Faheem
0
Faheem
Top achievements
Rank 1
answered on 06 Jul 2011, 09:45 AM
Hi Iva,
i am waiting of your reply, its kinda urgent

Regards
Faheem Khatri
0
Iva Toteva
Telerik team
answered on 07 Jul 2011, 10:40 AM
Hi Faheem,

All properties and elements that the format providers do not recognize are lost at the time the document is imported. Since the span's ID is only used to determine the style of the span, it cannot be retrieved at a later point in time. What is more, if you apply some formatting option on a span, it will be split into several others, new style classes will be added and the span's class will change accordingly.
If you need to keep track of parts of the document, you can try using Bookmarks. They are persisted along with their names and provide some methods that will enable you to programmatically detect, select and manipulate them.

Kind regards,
Iva
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Faheem
Top achievements
Rank 1
answered on 20 Jul 2011, 09:24 AM
Thanks for the reply
can you provide me example of bookmark which saves span id for example in it... and when i click on particular span it returns me the span id. because its difficult to find these kind of example.
0
Ivailo Karamanolev
Telerik team
answered on 21 Jul 2011, 03:36 PM
Hi Faheem,

The currently available method for what you want would be to preprocess the HTML and replace the id="span_id" attributes with <a name="span_id"> tags. These get imported as bookmarks. Then, after export, the process should be inverted. This pre and post-processing requires that the HTML is a well-formed XHTML document. If that is not the case, then this will not work.
We have no such demo available, but if you explain in greater detail your specific case, then we will be able to assist you further.

All the best,
Ivailo
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Faheem
Top achievements
Rank 1
answered on 21 Jul 2011, 05:21 PM
i have created a support ticket and added more detailed requirement over there, should i post here too?
0
Ivailo Karamanolev
Telerik team
answered on 22 Jul 2011, 04:10 PM
Hi Faheem,

Here's a demo on how to do an HTML import converting span ids to anchors and how to extract the text inside the bookmark ranges. Hope it helps.

Best wishes,
Ivailo
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Faheem
Top achievements
Rank 1
answered on 22 Jul 2011, 04:56 PM
its in silverlight and i dont have silver light controls, can you please provide me wpf project?

Edit:
Converted the project to WPF, on selection of span can i get the id of that selected span by bookmark (Anchor tag)? using current caret position or anything.
0
Accepted
Ivailo Karamanolev
Telerik team
answered on 25 Jul 2011, 02:18 PM
Hello Faheem,

You can enumerate all bookmarks in the document as in the example, using GetAllBookmarks. Then, for each bookmark, you can retrieve the start and end position (shown in the example) and by comparing them with the caret position, you can find the bookmarks which contain the caret position.

Greetings,
Ivailo
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
RichTextBox
Asked by
Faheem
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Faheem
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Share this question
or