Reputation: 1944
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.
Upvotes: 1
Views: 16854
Reputation: 12256
If all you need to do is force the input to upper case, try the CharacterCasing property of the textbox.
toUserTextBox.CharacterCasing = CharacterCasing.Upper;
Upvotes: 24
Reputation: 14133
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();
}
Upvotes: 3
Reputation: 103740
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();
}
Upvotes: 5