Skip to main content

Microsoft Silverlight

Unanswered Question Datagrid with tab navigationRSS Feed

(0)

Martin Kruszynski
Martin K...

Member

Member

15 points

27 Posts

Datagrid with tab navigation

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
R3al1ty

Member

Member

185 points

72 Posts

Re: Datagrid with tab navigation

Ouch, you are right. Cant Tab between cells in the DataGrid ... man, our users are going to scream.

Any workarounds from the experts?

AdmiralGanja
AdmiralG...

Member

Member

11 points

29 Posts

Re: Datagrid with tab navigation

I wonder what

TabNavigation= [cycle, once, local]

is intended to do... Doesn't seem to affect the tabnavigation between cells anyway...

/Jesper

R3al1ty
R3al1ty

Member

Member

185 points

72 Posts

Re: Re: Datagrid with tab navigation

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.

AdmiralGanja
AdmiralG...

Member

Member

11 points

29 Posts

Re: Re: Re: Datagrid with tab navigation

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
xusun

Participant

Participant

1015 points

167 Posts

Microsoft

Re: Re: Datagrid with tab navigation

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.

Thanks,
Xun Sun - MSFT

R3al1ty
R3al1ty

Member

Member

185 points

72 Posts

Re: Re: Re: Datagrid with tab navigation

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.

xusun
xusun

Participant

Participant

1015 points

167 Posts

Microsoft

Re: Re: Re: Datagrid with tab navigation

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

 

Thanks,
Xun Sun - MSFT

R3al1ty
R3al1ty

Member

Member

185 points

72 Posts

Re: Re: Re: Re: Datagrid with tab navigation

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
lee_sl

Contributor

Contributor

2992 points

585 Posts

Re: Re: Re: Re: Re: Datagrid with tab navigation

you can handle the currentcellchangedevent and call BeginEdit() to force the current cell to be go into editmode

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

SASilver
SASilver

Member

Member

46 points

29 Posts

Re: Re: Re: Re: Re: Datagrid with tab navigation

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
hehrsson

Member

Member

26 points

71 Posts

Re: Re: Re: Re: Re: Datagrid with tab navigation

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

lee_sl
lee_sl

Contributor

Contributor

2992 points

585 Posts

Re: Re: Re: Re: Re: Re: Datagrid with tab navigation

 

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

LarsHolmJensen
LarsHolm...

Member

Member

6 points

3 Posts

Re: Re: Re: Re: Re: Datagrid with tab navigation

 

private void SetCaretInCurrentCell()

{

dg.Dispatcher.BeginInvoke(
new Action(setCaretInCurrentCell));

}

private void setCaretInCurrentCell()

{

dg.BeginEdit();

dg.Focus();

}

puckoff7337
puckoff7337

Member

Member

71 points

57 Posts

Re: Re: Re: Re: Re: Datagrid with tab navigation

 Thanks, this thread was useful...

Cheers
-Cain

nivazone
nivazone

Member

Member

2 points

1 Posts

Re: Re: Re: Re: Re: Datagrid with tab navigation

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities