Click here to Skip to main content
12,246,406 members (39,825 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
how to convert first character of every word typed in a textbox to uppercase ?
Posted 22-Nov-12 0:02am
Comments
dimpledevani 22-Nov-12 5:05am
   
You can use the key pressed event and find out the ascii value of the character typed and replace it by its corresponding ascii code in capita
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

On text change event of textbox
txtbox.text = StrConv(txtbox.Text, vbProperCase)
Happy coding!
Smile | :)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        TextBox1.Text = StrConv(TextBox1.Text, vbProperCase)
    End Sub
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you can use following javascript function :

function initCap(str) {
    /* First letter as uppercase, rest lower */
    var str = str.substring(0, 1).toUpperCase() + str.substring(1, str.length).toLowerCase();
    document.getElementById('TextBox1').value = str;    
}

and call that function on onblur event of text box as shown below :

<asp:TextBox ID="TextBox1" onblur="return initCap(this.value)" runat="server"></asp:TextBox>
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Handle the TextBox.TextChanged event.
1) Save the TextBox.SelectionStart property.
2) Use the TextInfo.ToTitleCase Method[^] on the Text Property, saving the result in a new string variable
3) If the Text property is different from the new string, set the Text to the new string, and restore the SelectionStart property. Otherwise, do nothing.

If you don't do it this way, your cursor will move to the start of the TextBox every time you type a character (SelectionStart fixes this), or the event will enter an infinite loop (The equality test fixes this)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

make a button event
now you make not TOLOWER not TOUPPER you make totitlecase

Dim value As String = "du bi du da"
Dim title As String = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value)
Console.WriteLine(title)
'output:
' Du Bi Du Da
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100