Click here to Skip to main content
15,914,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a text box which accepts numeric and decimal values.

so now when the user selects the entire or part of the of the text in the text box and try to replace with a new value how can i do it?

please provide a sample code as am new to C#?
Posted

Just handle the TextChanged event - you get it when any change happens to the text, even if they replace the whole lot.
 
Share this answer
 
Comments
Member 10593922 13-Mar-14 5:18am    
in text changed event what code i have to write?
OriginalGriff 13-Mar-14 5:22am    
What code are you using at the moment?
Hi,

Some useful textbox control properties, methods and events:
Events:
1. TextChanged - Raised when content of Text property was changed
Properties:
1. TextBox.SelectedText - Allows you to get or set currently selected text
2. TextBox.SelectionStart - Gets or sets index of first selected character (0-based).
3. TextBox.SelectionLength - Gets or sets length of selected text

Methods:
1. TextBox.Select(start, length) - Allows you to select text from start index (0-based) with given length
2. TextBox.SelectAll() - Selects all text
 
Share this answer
 
v3
Comments
Member 10593922 13-Mar-14 5:23am    
thank u for the reply... am trying to use textbox.selectText event.. so can you please provide me a sample to replace the old value with the newly selected value in C#
Marcin Kozub 13-Mar-14 5:24am    
Please share your code
Member 10593922 13-Mar-14 5:32am    
if (txtPlannedHours.Text.Length > 0 )
{
txtPlannedHours.Text = txtPlannedHours.Text.Replace(txtPlannedHours.SelectedText, " ");
}


so now instead of null value , i want to display the value what the user has entered after selecting the entire or part of the text in the text box

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900