Welcome to the Xceed Community | Help
Community Search  

pressing Tab removes focus from datagrid

Sort Posts: Previous Next
  •  04-19-2007, 6:10 AM Post no. 7723

    pressing Tab removes focus from datagrid

    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
  •  04-19-2007, 9:10 AM Post no. 7724 in reply to 7723

    Re: pressing Tab removes focus from datagrid

    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...
    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  04-19-2007, 1:19 PM Post no. 7725 in reply to 7724

    Re: pressing Tab removes focus from datagrid

    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?
  •  04-20-2007, 11:24 AM Post no. 7726 in reply to 7725

    Re: pressing Tab removes focus from datagrid

    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?
  •  04-20-2007, 11:25 AM Post no. 7727 in reply to 7726

    Re: pressing Tab removes focus from datagrid

    dv is a DataView
  •  04-20-2007, 11:42 AM Post no. 7728 in reply to 7727

    Re: pressing Tab removes focus from datagrid

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

    Maybe this is a new feature in the latest release?
  •  04-23-2007, 8:22 AM Post no. 7729 in reply to 7728

    Re: pressing Tab removes focus from datagrid

    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
  •  05-03-2007, 11:34 AM Post no. 7730 in reply to 7729

    Re: pressing Tab removes focus from datagrid

    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
  •  08-20-2008, 6:20 PM Post no. 14272 in reply to 7730

    Re: pressing Tab removes focus from datagrid

    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

  •  08-25-2008, 8:39 AM Post no. 14439 in reply to 14272

    Re: pressing Tab removes focus from datagrid

    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.

  •  08-25-2008, 10:22 AM Post no. 14454 in reply to 14439

    Re: pressing Tab removes focus from datagrid

    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

    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  08-26-2008, 3:52 AM Post no. 14488 in reply to 14454

    Re: pressing Tab removes focus from datagrid

    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.

  •  08-26-2008, 8:19 AM Post no. 14500 in reply to 14488

    Re: pressing Tab removes focus from datagrid

    There is no way to "disable" this feature.

    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  08-26-2008, 11:37 AM Post no. 14507 in reply to 14500

    Re: pressing Tab removes focus from datagrid

    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);
                    }
                }
            }
     

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.