1

Closed

TextBoxTombstoner, Restore() failed

description

The Save() method uses : as delimiter between the Textbox.Text and SelectionStart und SelectionEnd.

When the TextBox contains an Url like "http://Myserver:8080/MyFile.txt" the Method Restore() fails.

A better implementation of Restore() (because we know there are 3 parts we have to split) is:

old ----------------------------------------------------------------------------
var detail = details.ToString().Split(':');
            (toRestoreTo as TextBox).Text = detail[0];

            (toRestoreTo as TextBox).SelectionStart = int.Parse(detail[1]);
            (toRestoreTo as TextBox).SelectionLength = int.Parse(detail[2]);
new ------------------------------------------------------------------------------------

string detailString = details.ToString();
            int lastColon = detailString.LastIndexOf(':');
            string str = string.Empty;
            // maybe I am paranoid
            if (lastColon >= 0) {
                str = detailString.Substring(lastColon + 1);
                (toRestoreTo as TextBox).SelectionLength = int.Parse(str);
                detailString = detailString.Substring(0, lastColon);
                lastColon = detailString.LastIndexOf(':');
                if (lastColon >= 0) {
                    str = detailString.Substring(lastColon + 1);
                    (toRestoreTo as TextBox).SelectionStart = int.Parse(str);
                    detailString = detailString.Substring(0, lastColon);

                }
            }
            (toRestoreTo as TextBox).Text = detailString;
Closed Sep 27, 2011 at 11:23 PM by mrlacey
Version 2.5 (just released) addresses this issue.

comments

mrlacey wrote Sep 27, 2011 at 11:23 PM

Version 2.5 (just released) addresses this issue.
Sorry it's taken so long but kudos for finding a work around.