Home Forums WPF controls Xceed DataGrid for WPF pressing Tab removes focus from datagrid

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22764 |

    Hi,

    I am having a problem with the datagrid component.
    In the samples the normal behavior of he grid is that pressing Tab moves the focus to the next cell in the grid, but in my application pressing Tab just removes focus from the grid and moves it to the parent element.
    I have been comparing the code of my application with the samples for a while now but I cannot find the problem…which is very frustrating 🙂

    Please advise.

    Cheers
    Arjan

    Imported from legacy forums. Posted by Arjan (had 7120 views)

    Xceed Support
    Member
    Post count: 5658

    Can you provide the XAML code used to initialize the DataGridControl? It would also help if you could provide any styles or templates applied to the grid or grid elements…

    Imported from legacy forums. Posted by Marcus [Xceed] (had 430 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes I have had this problem too.
    I havent solved the problem but I think mine is in a previewkeydown event
    do you use previewkeydown or keydown events?

    Imported from legacy forums. Posted by MiddleTommy (had 712 views)

    User (Old forums)
    Member
    Post count: 23064

    XAML:
    <TabItem Header=”TEST List”>
    <xcdg:DataGridControl x:Name=”dgTEST” AutoCreateColumns=”True”/>
    </TabItem>

    CodeBehind:

    dgTEST.ItemsSource = dv;

    these are the only two references to the grid in my test and the TAB still changes focus to another control

    I have multiple grids in my project (idea) is there an internal static property somewhere messing these up?

    Imported from legacy forums. Posted by MiddleTommy (had 797 views)

    User (Old forums)
    Member
    Post count: 23064

    dv is a DataView

    Imported from legacy forums. Posted by MiddleTommy (had 703 views)

    User (Old forums)
    Member
    Post count: 23064

    Holding Ctrl and TAB gives the results just pressing TAB used to.

    Maybe this is a new feature in the latest release?

    Imported from legacy forums. Posted by MiddleTommy (had 1025 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi all,
    I think part of the problem I was experiencing was caused by my data binding to an object.
    If not all properties used in the binding have a value then the TAB does not work properly.

    But now I have created my own datarow template and I’m experiencing the same problem.
    The purpose of the custom template is to visually split the columns of a data row into 2 lines (to prevent horizontal scrolling).
    Tabbing on the first line works, but tabbing on the second line causes the datagrid control to loose focus again.

    This is my Grid definition:

    <Grid Grid.Row=”1″ Grid.Column=”0″ Width=”Auto”>
    <Grid.Resources>
    <Style x:Key=”datarow_style” TargetType=”{x:Type xcdg:DataRow}”>
    <Setter Property=”Template”>
    <Setter.Value>
    <ControlTemplate TargetType=”{x:Type xcdg:DataRow}”>
    <Grid x:Name=”rootGrid”>
    <Grid.RowDefinitions>
    <RowDefinition Height=”Auto”/>
    <RowDefinition Height=”*”/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
    <!– GroupLevelIndicatorPane –>
    <ColumnDefinition Width=”Auto” />

    <!– CellsHost panel –>
    <ColumnDefinition Width=”175″ />
    <ColumnDefinition Width=”175″ />
    <ColumnDefinition Width=”175″ />
    <ColumnDefinition Width=”*” />
    </Grid.ColumnDefinitions>

    <!– The border responsible for the visual outline of the row (gridlines and background)
    spans the GroupLevelIndicatorPane and CellsHost Panel. Those 2 elements are not children of
    the Border because we don’t want the border to be displayed in the GroupLevelIndicatorPane. –>
    <Border x:Name=”rootBorder”
    Grid.Column=”0″
    Grid.ColumnSpan=”5″
    Grid.RowSpan=”2″
    BorderThickness=”1″
    BorderBrush=”AliceBlue”
    />

    <!– GroupLevelIndicatorPane is a placeholder for individual GroupLevelIndicator elements that are added
    whenever this Row is part of a group. –>
    <xcdg:GroupLevelIndicatorPane x:Name=”groupLevelIndicatorPane”
    Grid.Column=”0″ />

    <!– The PART_CellsHost part designates the Panel to which this Row’s Cells should be added.–>
    <StackPanel x:Name=”PART_CellsHost”
    Grid.Column=”1″
    Grid.ColumnSpan=”4″
    Grid.Row=”0″
    Orientation=”Horizontal” />
    <StackPanel Grid.Column=”1″
    Grid.Row=”1″
    Orientation=”Horizontal”>
    <xcdg:DataCell FieldName=”StartShip”/>
    </StackPanel>
    <StackPanel Grid.Column=”2″
    Grid.Row=”1″
    Orientation=”Horizontal”>
    <xcdg:DataCell FieldName=”StopShip”/>
    </StackPanel>
    <StackPanel Grid.Column=”3″
    Grid.Row=”1″
    Orientation=”Horizontal”>
    <xcdg:DataCell FieldName=”Style.Description”/>
    </StackPanel>
    <StackPanel Grid.Column=”4″
    Grid.Row=”1″
    Orientation=”Horizontal”>
    <xcdg:DataCell FieldName=”Style.FamilyName”/>
    </StackPanel>

    </Grid>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    <ControlTemplate x:Key=”datagrid_template”>
    <ScrollViewer x:Name=”PART_ScrollViewer”>
    <WrapPanel IsItemsHost=”True” Orientation=”Horizontal”/>
    </ScrollViewer>
    </ControlTemplate>
    </Grid.Resources>
    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemContainerStyle=”{StaticResource datarow_style}”
    Template=”{StaticResource datagrid_template}”
    AutoCreateColumns=”False”
    EditTriggers=”CellIsCurrent”
    NavigationBehavior=”RowOrCell”>
    <xcdg:DataGridControl.View>
    <xcdg:TableView ShowRowSelectorPane=”True”>
    <xcdg:TableView.Theme>
    <xcdg:AeroNormalColorTheme/>
    </xcdg:TableView.Theme>
    </xcdg:TableView>
    </xcdg:DataGridControl.View>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”Style.Code” Title=”Style” Width=”175″/>
    <xcdg:Column FieldName=”Style.Color” Title=”Color” Width=”25″/>
    <xcdg:Column FieldName=”Style.Dimension” Title=”Dim” Width=”25″/>
    <xcdg:Column FieldName=”CoordinateCode” Title=”Co” Width=”25″/>
    <xcdg:Column FieldName=”B1″ Width=”25″/>
    <xcdg:Column FieldName=”B2″ Width=”25″/>
    <xcdg:Column FieldName=”B3″ Width=”25″/>
    <xcdg:Column FieldName=”B4″ Width=”25″/>
    <xcdg:Column FieldName=”B5″ Width=”25″/>
    <xcdg:Column FieldName=”B6″ Width=”25″/>
    <xcdg:Column FieldName=”B7″ Width=”25″/>
    <xcdg:Column FieldName=”B8″ Width=”25″/>
    <xcdg:Column FieldName=”B9″ Width=”25″/>
    <xcdg:Column FieldName=”B10″ Width=”25″/>
    <xcdg:Column FieldName=”B11″ Width=”25″/>
    <xcdg:Column FieldName=”B12″ Width=”25″/>
    <xcdg:Column FieldName=”Quantity” Title=”Qty” Width=”30″ ReadOnly=”True”/>
    <xcdg:Column FieldName=”PricePerUni

    Imported from legacy forums. Posted by Arjan (had 1093 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,
    I’m still having this issue with tabbing in the grid control.

    In the meantime I have noticed that the tabbing stops working if you explicitly used DataCell (or InsertionCell) elements to define a DataRow template (or InsertionRow template respectively).

    Hopefully this extra information is enough for somebody to come with a solution. It would be much appreciated!

    Cheers
    Arjan

    Imported from legacy forums. Posted by Arjan (had 6568 views)

    User (Old forums)
    Member
    Post count: 23064

    I am still having this issue too.

    For me when the Grid is in edit mode tab is fine. otherwise TAB removes focus from the grid

    Imported from legacy forums. Posted by MiddleTommy (had 742 views)

    User (Old forums)
    Member
    Post count: 23064

    Same problem here. When a row is in edit mode and I press TAB the next cell is activated and all text selected as expected.

    But press Enter and then TAB and the grid loses focus.

    I am unable to repreduce this with a simple “hello world” application, but it is present in our full aplication.

    Imported from legacy forums. Posted by Du Toit (had 933 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,
     
       Just to clarify, this behavior is in fact by design.

       Tabbing or Shift-Tabbing will cycle the focus through the controls in the page/window. The fact that Tab/Shift-Tab will move focus from cell to cell when a row is in edition is a feature we added to enable fast user input scenarios. To navigate within the DataGridControl while it has focus, arrow keys  ( directional navigation ) should be used.

       There is

    Imported from legacy forums. Posted by Marcus [Xceed] (had 899 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Marcus.

    Thanks for the reply. Is there any way to disable this behavior?

    It is not a big problem if it cannot be turned off, but it would help retain functionality we currently have in our WinForms application.

    Thank you.

    Imported from legacy forums. Posted by Du Toit (had 670 views)

    Xceed Support
    Member
    Post count: 5658

    There is no way to “disable” this feature.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 684 views)

    User (Old forums)
    Member
    Post count: 23064

    Here is my workaround

    You can derive from gridcontrol and override On(Preview)KeyDown/Up or catch the (Preview)KeyDown/Up events (which ever you like best for your situation)

     

          if (e.Key == Key.Enter || e.Key == Key.Tab)
                {
                    CustomDataGridControl grid = this;
                    Column c = grid.CurrentColumn;
                    if (c!=null && !c.HasValidationError)
                    {
                        int pos = grid.VisibleColumns.IndexOf(c);
                        if (pos >= grid.VisibleColumns.Count – 1)
                        {
                            e.Handled = true;
                            c = grid.VisibleColumns[0];
                        }
                        else
                        {
                            e.Handled = true;
                            c = grid.VisibleColumns[pos + 1];
                        }
                        DataRow cdr = grid.GetContainerFromItem(grid.CurrentItem) as DataRow;
                        if (cdr != null && !cdr.HasValidationError)
                        {
                            try
                            {
                                //cdr.EndEdit();//Removed becasue it is not needed in Grid 3.0 to update other cells
                                if (!cdr.HasValidationError)
                                {
                                    UpdateSelected();//used for updating all selected rows with the current change
                                    grid.CurrentColumn = c;
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.Write(ex.ToString());
                            }
                        }
                        else
                            e.Handled = false;
                    }

                }

     

    //—————————————————————

     

            private void UpdateSelected()
            {
                //edit all selected rows
                CustomDataGridControl grid = this;
                string col = grid.CurrentColumn.FieldName;
                object si = grid.CurrentItem;
                Type t = si.GetType();
                PropertyInfo pi = t.GetProperty(col);
                object val = pi.GetValue(si, null);
                if (pi != null)
                {
                    foreach (object r in grid.SelectedItems)
                    {
                        if (!r.Equals(si))
                            pi.SetValue(r, val, null);
                    }
                }
            }
     

    Imported from legacy forums. Posted by MiddleTommy (had 856 views)

    User (Old forums)
    Member
    Post count: 23064

    Has there been anything added to the latest version of the datagrid to accommodate this behavior? My users will kill me if I take away their tab key functionality. When we switched over from VB6 to .net windows forms the users were very upset that the tab key did not behave the way they expected. They also wanted the ability to tab to the next row when the final column of a row had keyboard focus. Microsoft’s windows forms and wpf datagrids support this type of tabbing behavior, and it is familar to users of many microsoft applications.

    Imported from legacy forums. Posted by Philip (had 1477 views)

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.