Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
550
ActiveCell.SelText and ActiveCell.SelStart are not always congruent
posted

I have a cell/column that has a mask editor associated with it. Since it is possible to select the masking characters ("_") in the cell, the SelStart can report the wrong index.

For example:

ActiveCell.Value = "45851"
ActiveCell.EditorResolved.CurrentEditText  = "_____45851"
User selects "851"
ActiveCell.SelText = "851"
ActiveCell.SelStart = "7"
Dim SelectedString As String = ActiveCell.SelText
Dim SelectedStart As Integer = ActiveCell.SelStart
Dim ValueString As String = ActiveCell.Value
ValueString = Value.SubString(SelectedStart, SelectedString.Length) 'Throw an error because index 7 does not belong to Value

I'm already having to do a workaround having to remember the selected text and selection start when the grid loses focus. I'm not sure what kind of workaround I can do with this.

Ideas?

Parents
  • 71886
    Offline posted

    Hello chatelain,

    I hope that I got your requirements and scenario right. I think that you could use the 'LastIndexOf' method of the 'string' class.

    Something like this:

          Value.ToString().LastIndexOf('_');

    When you get the index you can use it in calculations and this way you will know from what index exactly does your real value start.

    Please feel free to let me know if I misunderstood you or if you have any other questions.

Reply Children