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
100
Spinner Issue
posted

Hi,

I am using a Textbox of type Ultra Text Editor in my Windows Form.But I was in need of a requirement that I want to enter a quantity in that textbox and when I enter any numbers it should also put commas automatically as a thousand comma separator format.

Earlier I used Ultra Numeric Editor also but the problem in using that was that it is displaying digits after decimal by default.But my requirement was that decimals should not be visible by default but in case if user wants to enter the decimal digits then he should be able to enter it in the textbox.So finally I decided to use textbox of Ultra Text Editor type.I achieved my task of putting automatic commas in the textbox.

Now the problem I am facing is that when I enter digits till 3 digits for example. 978 it is working fine but as soon as I enter the 4th digit viz. 6 then my no. shows as 9,786(yeah it's perfect) but the cursor inside my textbox automatically moves to the starting in this case before 9 so before putting next digit every time I have to manually change the cursor position.I want that my cursor position automatically set to the current position.

I also searched on net an d I found TextBox.SelectionStart andTextBox.SelectionLength properties but they are setting the position to the end or start but suppose the user entered 98736352 and till now the data is showing as 98,736,352 and the cursor is after digit '2' as i have setted its Selection Start position to the end  but if suppose user goes and deleted digit '7' then i will see 9,836,352 but my cursor again goes to after digit '2' so if user deleted digit '7' but if he also wants to delete digit '3' then firstly he have to again manually bring cursor to the digit position and that will cause inconvenience. 

So is there any way to control the cursor position in textbox in the way I want or may be there is some other way to handle my requirement. Please suggest.Waiting for your reply.

Thanks,

Kashish Goyal

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Kashish, 

    The UltraTextEditor doesn't have any built-in functionality to insert commas. So if you are getting the commas to show up, presumably you must be handled an event of the control, like TextChanged and inserting them yourself. This is going to be extremely tricky, and you noted that the cursor position is wrong in your case.

    I can't say why the cursor positioning is changing without knowing what your code is doing, though. It should certainly be possible to restore the cursor position by setting SelectionStart, but if the SelectionStart on the UltraTextEditor doesn't work while the control is in edit mode, then you may be able to acheive what you want by using the embedded TextBox instead.

    When it is in edit mode, the UltraTextEditor contains a TextBox control within it. You can access it like this:

    TextBox textBox = this.UltraTextEditor1.Controls[0] as TextBox;

    Then you can set the SelectionStart and SelectionLength on the TextBox and that should give you total control over the cursor position.

Children
No Data