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
300
Wrong cursor position after setting Editor.SelectionStart
posted

Hallo! I have a following code in my derived from UltraCurrencyEditor control:

 

public class MyUltraCurrencyEditor : Infragistics.Win.UltraWinEditors.UltraCurrencyEditor {

...
	protected override void OnClick(EventArgs e)
	{
		base.OnClick(e);
		var decimalSeparator = (System.Globalization.CultureInfo)FormatProvider).NumberFormat.CurrencyDecimalSeparator;
		var separatorPosition = Editor.CurrentEditText.LastIndexOf(decimalSeparator);
			if (Editor.SelectionStart > separatorPosition)
				Editor.SelectionStart = separatorPosition;
		}
}

The expected behaviour: if the control is clicked right from currency decimal separator (comma), the cursor will be positioned before it. It works OK if the currensy has no group separators (points). But if the currency amount is greather than 1.000,00 - the cursor jumps to the position after coma. And in case of 1.000.000,00 - after a first zero character after comma. It seems to me a bug. What are you suggestions?

Best Regards

Андрей Вилинский

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    I took a look at this and I think I see the problem.

    CurrentEditText is a string, and so the LastIndexOf method is just basing the position it returns on an ordinary string value.

    But the positions in the CurrencyEditor are not all valid positions. The digit grouping character (the decimal points in this case) are not valid positions. You can see this if you arrow through the control using the keyboard. The decimal points are skipped and the caret advances two places to skip over them.

    So to get this to work the way you want, you would have to count the number of digit grouping characters before the separator position and subtract those in order to determine the correct position.

Children
No Data