views:

1221

answers:

3

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.

+5  A: 

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();
}
BFree
Bingo. You can't just call a function on a string without reassigning it.
TheTXI
Lol... I'll blame it on fatigue :P
Sakkle
+2  A: 

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();
}
Romias
+4  A: 

If all you need to do is force the input to upper case, try the CharacterCasing property of the textbox.

toUserTextBox.CharacterCasing = CharacterCasing.Upper;
John Myczek