Exemple #1
0
        public static void SetFocusToGrid(DataGrid targetGrid, int index = -1)
        {
            // no items
            if (targetGrid.Items.Count < 1)
            {
                return;
            }
            // keep current row selected
            if (index == -1 && targetGrid.SelectedIndex > -1)
            {
                index = targetGrid.SelectedIndex;
            }
            // if no item selected, pick first
            if (index == -1)
            {
                index = 0;
            }
            targetGrid.SelectedIndex = index;
            // set full focus
            DataGridRow row = (DataGridRow)targetGrid.ItemContainerGenerator.ContainerFromIndex(index);

            if (row == null)
            {
                targetGrid.UpdateLayout();
                // scroll to view if outside
                targetGrid.ScrollIntoView(targetGrid.Items[index]);
                row = (DataGridRow)targetGrid.ItemContainerGenerator.ContainerFromIndex(index);
            }
            // NOTE does this causes move below?
            row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
            row.Focus();
            Keyboard.Focus(row);
        }
        private void SelectRowDetails(object sender, MouseButtonEventArgs e)
        {
            var         ogSource  = e.OriginalSource;
            var         source    = e.Source;
            DataGridRow parentRow = FindVisualParent <DataGridRow>(sender as DataGridDetailsPresenter);
            DataGridRow childRow  = FindVisualParent <DataGridRow>(ogSource as UIElement);
            Button      button    = FindVisualParent <Button>(ogSource as UIElement);
            DataGrid    childGrid = FindVisualParent <DataGrid>(childRow);

            if (parentRow == null ||
                (childRow != null && childRow.IsSelected == true && childGrid.SelectedItems.Count == 1) ||
                (childRow == null && button == null))
            {
                return;
            }
            parentRow.Focusable = true;
            parentRow.Focus();

            var focusDirection   = FocusNavigationDirection.Next;
            var request          = new TraversalRequest(focusDirection);
            var elementWithFocus = Keyboard.FocusedElement as UIElement;

            if (elementWithFocus != null)
            {
                elementWithFocus.MoveFocus(request);
            }
        }
Exemple #3
0
        private void btnAddNZYDKData_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            int    index;

            if (int.TryParse(button.Tag.ToString(), out index))
            {
                DataGridRow row = (DataGridRow)dkGrid.ItemContainerGenerator.ContainerFromIndex(index);
                row.Focus();
            }
        }
Exemple #4
0
        private void dgmenu1_Cilck(object sender, MouseButtonEventArgs e)
        {
            Point         p   = e.GetPosition(this.datagrid_cpk);
            HitTestResult htr = VisualTreeHelper.HitTest(this.datagrid_cpk, p);
            TextBlock     o   = htr.VisualHit as TextBlock;

            if (o != null)
            {
                DataGridRow dgr = VisualTreeHelper.GetParent(o) as DataGridRow;

                dgr.Focus();
                dgr.IsSelected = true;
            }
        }
Exemple #5
0
        public void btnDodajWiersz_Click(object sender, RoutedEventArgs e)
        {
            dodaj = true;
            lblStronaZusZla.Content      = "";
            gridKodZusZla.CanUserAddRows = true;
            DataGridRow row = gridKodZusZla.ItemContainerGenerator.ContainerFromIndex(wiersz) as DataGridRow;

            ZusZlaFormatView(Convert.ToInt32(ZusZlaView.Add));

            for (int i = 0; i < gridKodZusZla.Items.Count; i++)
            {
                row = gridKodZusZla.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
                //Hide all lines except the newly added
                if (row != null)
                {
                    row.Focus();
                    row.Visibility = Visibility.Collapsed;
                }
            }
        }
 private void HighlightRows()
 {
     for (int i = 0; i < dgBooks.Items.Count; i++)
     {
         dgBooks.UpdateLayout();
         dgBooks.ScrollIntoView(dgBooks.Items[i]);
         DataRowView rowview = dgBooks.Items[i] as DataRowView;
         DataGridRow row     = (DataGridRow)dgBooks.ItemContainerGenerator.ContainerFromIndex(i);
         var         val     = rowview.Row.Field <string>("InStock");
         if (val != null && val.Equals("False"))
         {
             object item = dgBooks.Items[i];
             dgBooks.SelectedItem = item;
             dgBooks.ScrollIntoView(item);
             row.Focusable  = true;
             row.IsSelected = true;
             row.Focus();
         }
     }
 }
Exemple #7
0
        private void SelectedHandler(object sender, System.Windows.RoutedEventArgs e)
        {
            DataGridRow dataGridRow = sender as DataGridRow;

            dataGridRow?.Focus();
        }
Exemple #8
0
        private void PreviewMouseLeftButtonDown_OnHandler(object sender, MouseButtonEventArgs e)
        {
            DataGridRow dataGridRow = sender as DataGridRow;

            dataGridRow?.Focus();
        }