Setting the contents of a textBox to upper-case on CurrentItemChanged
-
03-07-2019 - |
Question
I would like the text in my textBox to be set to upper-case whenever currentItemChanged is triggered. In other words, whenever the text in the box changes I'd like to make the contents upper-case. Here is my code:
private void rootBindingSource_CurrentItemChanged(object sender, System.EventArgs e)
{
toUserTextBox.Text.ToUpper();
readWriteAuthorization1.ResetControlAuthorization();
}
The event triggers for sure, I've tested with a messageBox. So I know I've done something wrong here... the question is what.
Solution
Strings are immutable. ToUpper() returns a new string. Try this:
private void rootBindingSource_CurrentItemChanged(object sender, System.EventArgs e)
{
toUserTextBox.Text = toUserTextBox.Text.ToUpper();
readWriteAuthorization1.ResetControlAuthorization();
}
OTHER TIPS
If all you need to do is force the input to upper case, try the CharacterCasing property of the textbox.
toUserTextBox.CharacterCasing = CharacterCasing.Upper;
I imagine that your question is Why your code is not working.
You are not assigning the "Uppered" text to the textbox again.
Should be:
private void rootBindingSource_CurrentItemChanged(object sender, System.EventArgs e)
{
toUserTextBox.Text = toUserTextBox.Text.ToUpper();
readWriteAuthorization1.ResetControlAuthorization();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow