.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Assign or insert text into TextBox In Silverlight

Posted By:Diptimaya Patra       Posted Date: March 22, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

There are various requirements for the TextBox Text input. In this article we will see how can we insert text in any TextBox Caret position
 

Introduction

There are various requirements for the TextBox Text input. In this article we will see how can we insert text in any TextBox Caret position.

Creating Silverlight Project

Fire up Visual Studio 2008 and create a new Silverlight 3 Project. Name it as TextInsert.

1.gif 

Here is the idea, there will be a list of Text in a combo box and we need to add the selected Text from the ComboBox to the caret position of TextBox.

Open the solution and design the page as follows.

2.gif

Now insert some text to the ComboBox in the application load.

public MainPage()
{
  InitializeComponent();
  List myList = new List() 
  {
 "[UserName]","[Sender]", "[UserContact]", "[UserAddress]"
  };
  cmbTexts.ItemsSource = myList;
}

Now create an event handle of ComboBox SelectionChanged.

SelectionChanged
="cmbTexts_SelectionChanged"

Add the following code into the above handler.

private void cmbTexts_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  string selected = txtMyTextBox.Text;
  int positionNotificationTemplate = txtMyTextBox.SelectionStart;
  string strTemp1 = cmbTexts.SelectedItem.ToString();
  selected = selected.Insert(positionNotificationTemplate, strTemp1);
  txtMyTextBox.Text = selected;
}

Now run the application and write your message in TextBox.

3.gif

Hope this article is helpful to all.
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend