Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Invalid key event handling on text box in datagrid
6 replies. Latest Post by joer00 on May 15, 2008.
(0)
joer00
Member
145 points
113 Posts
05-08-2008 8:58 AM |
I try to work around the bug i reported that textbox with accept return does not work in data grid. Looking into the data grid code I see that key events are not processes if the handled is set to true. So I thought I wrap my textbox in a grid and call set handled=true in the grids keydown event.
This indeed prevents the data grid from processing, but now I can only enter backspace in my text cell ! As far as I understand events bubble UP not down as it is possible in WPF. From debug I can see that the TextBox key down event is indeed fired BEFORE the Grids key down event. So why can't I enter text ?
{
}
Yi-Lun L...
All-Star
25052 points
2,747 Posts
05-13-2008 3:03 AM |
Hello, you can manually insert a line break to a TextBox in a DataGrid. Try something like this:
sb.Append(tb.Text.Substring(0, start));
sb.Append(tb.Text.Substring(start + tb.SelectionLength));
tb.Text = sb.ToString();
tb.Select(start + 1, 0);
05-13-2008 9:17 AM |
As I mentioned in my previous post, setting the e.handled to true results in NO key accepted in the textbox but the backspace key. It might work to manually construct the text box text for ANY key input. I did not check this as I worked around the problem by putting a non gird text box above the gird one on enter.
05-13-2008 11:03 PM |
You don't need to handle all keys. You only need to handle the Enter key.
//Handle Enter yourself.
//Other keys will still be handled by the TextBox.
05-14-2008 7:54 AM |
Yi Lun,
as I posted in this thread http://silverlight.net/forums/p/15454/51043.aspx#51043 calling e.Cancel results in NO KEY entered into the text box ! That's why I was posting one has to try to manually add ALL keys. So please try it our, maybe my setup is special as I use a custom control in the details view of the DataGrid row. And once again, setting e.Cancel on the KeyDown event of the gird results in NO KEY appearing in the text box.
05-15-2008 12:19 AM |
Yes, I understand setting e.Handled to true will prevent TextBox from entering keys. That's why I suggest you only to set e.Handled to true when the key is Enter. For other keys, you can keep e.Handled as false. Maybe this will make you feel more confertable:
else
e.Handled = false;
05-15-2008 8:00 AM |
ah sorry, stupid me I did not read it correctly :) That should work now.
Thanks