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,
I am checking about the progress of this issue. Please let me know If you need any further assistance on this.
Hi,
It seems like the problem here is that you are treating Value as a string. If you are manipulating text, then you should be using the Text property or possibly the GetText method to get the whole text string.
Hello chatelain,
I got confused here. I am not sure what is your final goal. I would suggest you to use string.Replace("_", ""); but I am not sure this will work either. Could you please try to clarify your goal. Thank you in advance.
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.
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.