|
-
Jun 7th, 2013, 08:51 AM
#1
Thread Starter
Frenzied Member
Strange code, how make it better?
Hi!
I stumbled upon this code in a project
Code:
private void TextBox_KeyDown(object sender, KeyEventArgs e) {
var t = (TextBox)sender;
if (t.IsReadOnly == true && e.Key != Key.F2) {
t.Text = "";
t.IsReadOnly = false;
}
if (e.Key == Key.F2) {
t.IsReadOnly = false;
t.CaretIndex = t.Text.Length;
t.Cursor = Cursors.IBeam;
e.Handled = true;
}
}
I asked around and it seems like there is a requirement that a cell in a datagrid shoould get some "excel-like" behaviour. For example, when you select a cell and start type, the existing text disappear, and when you press f2 or double click, the cursor should be positioned at the end of the text.
Im a web guy myself and want to ask the experts here ifall this code is really needed, and if something can be done to make it look more "pretty", for example, is e.handle really needed and what about the if- statements?
kind regards
Henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|