Click here to Skip to main content
16,004,412 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a textbox which accepts hours.
so now when i select the entire or part of the text , i should be able to replace.


so how can i achieve this condition in C#?


Am trying with the below condition
txtPlannedHours.Text = txtPlannedHours.SelectedText.Replace(txtPlannedHours.Text,"");


is it correct format?
Posted

Should be like this:
C#
txtPlannedHours.Text = txtPlannedHours.Text.Replace(txtPlannedHours.SelectedText,"");
 
Share this answer
 
Comments
Member 10593922 13-Mar-14 2:25am    
thank u for the reply... for ex: if i have 12.5 as a value in the textbox, and when i only select 5, and try to replace with 2, its not happening.
because we are giving the value to replace as null,
so how can i make the replaced value visible?
All you need is:
C#
textBox1.Text = textBox1.SelectedText;
The TextBox Control in Win Forms retains any selection when it loses focus; however, if you think there's a danger of somehow losing the selection, you could always define a TextChanged EventHandler, and update a variable with the current SelectedText.
 
Share this answer
 
Comments
Member 10593922 13-Mar-14 4:41am    
please provide a sample..

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