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?