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.SelTextDim SelectedStart As Integer = ActiveCell.SelStartDim ValueString As String = ActiveCell.ValueValueString = 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?
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.
Value does not contain the masked characters. Only ActiveCell.EditorResolved.CurrentEditText has it. The challenge is that not always is the cell editor a mask but could be a text editor which would allow "_" to be entered which makes LastIndexOf not work well.
Hello,
I am checking about the progress of this issue. Please let me know If you need any further assistance on this.