I’ve created a TextBox in which currency values have to be entered but now I am not able to enter .(dot) in the textbox for decimal values. I have written the code in Text_changed event.
The code
int cursorLocation = ((TextBox)(sender)).SelectionStart;
string inputval = ((TextBox)sender).Text;
inputval = inputval.Replace("*", "");
inputval = inputval.Replace("#", "");
inputval = inputval.Replace(",", "");
inputval = inputval.Replace(" ", "");
inputval = inputval.Replace("-", "");
Decimal inputval1 = Convert.ToDecimal(inputval);
((TextBox)sender).Text = inputval1.ToString("###,###");
cursorLocation = ((TextBox)(sender)).Text.Length;
//((TextBox)sender).Text = inputval;
((TextBox)(sender)).SelectionStart = cursorLocation;
I just did this under textchanged event and this worked,