Hi!
I stumbled upon this code in a project
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
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;
}
}
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