10
Vote

DataGrid: The ESC and Backspace key produces an unrecognized character

description

Select a DataGridTextColumn cell and press the ESC or Backspace key. Then the cell enters the edit mode and shows an unrecognized character ('[]') in the TextBox.

However, the behavior should be similar to Microsoft Excel.
1) ESC doesn't do anything when the cell is not in edit mode.
2) The Backspace key should delete the content of the cell and it should enter the edit mode.

No files are attached

comments

sologut wrote Dec 30 2011 at 11:54 AM

It looks strange to me... why it's still Unassigned?..

Arrow_Raider wrote Jan 31 2011 at 6:22 PM

The bug involving the backspace key is still not fixed in the .net 4.0 datagrid. This is absolutely unacceptable. This bug should have been fixed before the datagrid was released as part of .net 4.0. Now that .net 4.0 has been out for almost a year, it seems unlikely this problem will be fixed before the next major release of .net.

Blackbox wrote Dec 12 2009 at 1:17 PM

Please fix this.
Thanks!

tommywtf wrote Nov 4 2009 at 1:58 AM

I have the same problem.~~
Please fix it.
Thanks!

aranm wrote Aug 21 2009 at 12:56 AM

the escape issue that is, to fix the backspace one i derive from DataGridTextColumn and change the start of the method as so

protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) {
TextBox textBox = editingElement as TextBox;
if (textBox != null) {
string originalValue = textBox.Text;

TextCompositionEventArgs textArgs = editingEventArgs as TextCompositionEventArgs;
if (textArgs != null) {
string inputText = String.Empty;
// If text input started the edit, then replace the text with what was typed, unless it was the backspace key (then just replace it with String.Empty
if (textArgs.Text == "\b") {
//backspace was pressed
}
else {
inputText = textArgs.Text;
}
textBox.Text = inputText;

etc....

aranm wrote Aug 21 2009 at 12:52 AM

Code i use to fix the issue, although it does involving deriving from the grid:

public class DerivedDataGrid : DataGrid {

protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e) {

switch (e.Key) {
case System.Windows.Input.Key.Escape:

if (Items == null) { }
else {
IEditableCollectionView collectionView = Items as IEditableCollectionView;
if (collectionView == null) { }
//if we are in cell edit mode do nothing
else if (collectionView.IsEditingItem && collectionView.CurrentEditItem == this.CurrentCell.Item) { }
else {
//otherwise we are not editing, mark the event as handled so it does no damage
e.Handled = true;
}

}
break;
}
//pass other massages to the base
if (e.Handled == false) {
base.OnKeyDown(e);
}
}
}

VamseeP wrote Jul 7 2009 at 8:11 PM

We agree that this is a bug in June toolkit and we have it logged in our internal database.

tonytam wrote Jul 7 2009 at 1:19 AM

I have the same problem.

jbe2277 wrote Jul 2 2009 at 2:08 PM

Code to reproduce the issue:

<wpf:DataGrid ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson}" AutoGenerateColumns="False" CanUserAddRows="False">
<wpf:DataGrid.Columns>
<wpf:DataGridTextColumn Header="First Name" Binding="{Binding Firstname}"/>
<wpf:DataGridTextColumn Header="Last Name" Binding="{Binding Lastname}"/>
<wpf:DataGridTextColumn Header="Age" Binding="{Binding Age}"/>
</wpf:DataGrid.Columns>
</wpf:DataGrid>


I'm using the WPF Toolkit June 2009 release.