Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Datagrid with tab navigation
15 replies. Latest Post by nivazone on September 7, 2009.
(0)
Martin K...
Member
15 points
27 Posts
09-21-2008 3:46 PM |
1. With Silverlight 2 beta 2 DataGrid you can't go next cell by pressing tab key (or previous by pressing tab + shift).
2. When DataGrid gets focus the last used cell gets focus instead of first cell.
WPF toolkit DataGrid has navigation by tabbing and first cell always gets focus when DataGrid gets focus.
How can I add tab navigation to Silverlight DataGrid? Can I write keydown event handler or custom DataGrid?
Do you know any samples of tab navigation with Silverlight DataGrid?
Martin
R3al1ty
185 points
72 Posts
09-30-2008 5:55 AM |
Ouch, you are right. Cant Tab between cells in the DataGrid ... man, our users are going to scream.
Any workarounds from the experts?
AdmiralG...
11 points
29 Posts
09-30-2008 7:24 AM |
I wonder what TabNavigation= [cycle, once, local]
TabNavigation
is intended to do... Doesn't seem to affect the tabnavigation between cells anyway...
/Jesper
10-16-2008 10:14 PM |
Could a microsoftie respond, its a bit too much to ask users to click each cell with the mouse in a real-world app. Thanks.
10-17-2008 2:46 AM |
This is probably because the browser already handled it. So if anyone know how to catch and prevent that event from being handled by the browser it might be the solution, but still I guess this is very browser specific, and could not be handled in code... Please proove me wrong anyone?
R3al1ty: At least the users could navigate in the DataGrid with the arrow keys, but I defenitely concur with you... Please Microsoft staff, help us out here with this usability issue!?
xusun
650 points
100 Posts
10-18-2008 8:49 AM |
First of all, DataGrid does support Tab navigation. Tab navigation is supported when the datagrid is in Editing mode, i.e. after double clicking a cell. While not in editing mode, users can still use Arrow keys to navigate the cells.
However, there is a bug not fixed in RTM. When the datagrid is the last element in your panel, Tab navigation will not work. It will navigate to the address bar. The walk-around is to add something after the datagrid, for example, a ContentControl.
10-18-2008 11:59 AM |
Hey thanks, that works!
...but, if I have a couple of TextBoxes in a row as my CellTemplates, if I type something inside one of them and Tab to the next, the next cell switches to a TextBox but I have to click once more inside before I can type something in.
10-18-2008 12:14 PM |
This is because you are using CellTemplates. The DataGrid only knows that it needs to use the CellEditTemplate for that cell after you hit Tab and show you the content in your CellEditTemplate. It doesn't know which element in your CellEditTemplate should get focus. I suggest the following:
1. If it's equvalent to a TextColumn, you may consider to restyle it to meet your requirement and let the default DataGrid behavior do the focus for you; Or
2. You can hook up some event to make the textbox gets focus when the cell gets focus
10-23-2008 10:55 PM |
Thanks, could you elaborate on how I could achieve pt 2 on this basic template? I am trying to see if there is a generic way I can achieve this....<CellEditingTemplate><Grid><TextBox Text="{Binding Name}"/></Grid></CellEditingTemplate>
lee_sl
Contributor
2990 points
584 Posts
10-28-2008 6:29 AM |
you can handle the currentcellchangedevent and call BeginEdit() to force the current cell to be go into editmode
SASilver
46 points
11-17-2008 4:30 AM |
My datagrid has many of the cells as editing templates and i also tried hooking the event Begin Edit... But dint work right for me.
How did u guys solve it ?
hehrsson
26 points
71 Posts
11-20-2008 5:49 AM |
Same problem for me, the BeginEdit will bring the TextBox in focus but the caret is not displayed.
Before I tried this, clicking once with the mouse in a cell would mark the cell with a blue border around it.Clicking a second time would bring up the TextBox specified in CellEditingTemplate (the background in the cell becomes white instead of blue), but I could still not write anything into the TextBox.Clicking a third time would make the TextBox editable.After I tried the BeginEdit() stuff I managed to get rid of the first step (just marking the cell), but I still need two clicks to get the caret displayed in the TextBox making it possible to write anything.
I have the same demand from my customers, navigating the grid with the Enter key, but with an addition, when pressing Enter in the last cell on the last row, a new empty row should be added (I'm creating an invoice registration form where you add invoice rows in the grid).
- Håkan
01-15-2009 4:02 PM |
LarsHolm...
6 points
3 Posts
05-27-2009 3:36 AM |
private void SetCaretInCurrentCell() {dg.Dispatcher.BeginInvoke(new Action(setCaretInCurrentCell)); }private void setCaretInCurrentCell() { dg.BeginEdit(); dg.Focus(); }
{
}
dg.BeginEdit();
dg.Focus();
puckoff7337
70 points
53 Posts
07-29-2009 6:21 AM |
Thanks, this thread was useful...
nivazone
2 points
1 Posts
09-07-2009 8:40 PM |
I had the exact same problem, what I did to overcome double tabbing is;
- Call BeginEdit() in CurrentCellChanged event of the datagrid
- Use PreparingCellForEdit event of the datagrid to get EditingElement (which is in DataGridPreparingCellForEditEventArgs), and locate ComoBox or TextBox by scanning visual tree.
- Once you found the control, set it to focus using Focus() method.
Hope this helps.