private void PhoneBook_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { if (sender is Microsoft.Windows.Controls.DataGridCell) { Microsoft.Windows.Controls.DataGridCell tempcell = sender as Microsoft.Windows.Controls.DataGridCell; Microsoft.Windows.Controls.DataGridRow row = null; var parent = VisualTreeHelper.GetParent(tempcell); while (parent != null && parent.GetType() != typeof(Microsoft.Windows.Controls.DataGridRow)) { parent = VisualTreeHelper.GetParent(parent); if (parent is Microsoft.Windows.Controls.DataGridRow) { row = parent as Microsoft.Windows.Controls.DataGridRow; break; } } if (row != null) { Pointel.Interactions.Chat.Helpers.Contacts selectedContact = (Pointel.Interactions.Chat.Helpers.Contacts)row.Item; dgvContact.SelectedItem = (Pointel.Interactions.Chat.Helpers.Contacts)row.Item; _phoneBookText = selectedContact.Number; _phoneBookMenu.PlacementTarget = row; _phoneBookMenu.IsOpen = true; } } }
static Microsoft.Windows.Controls.DataGridCell TryToFindGridCell(Microsoft.Windows.Controls.DataGrid grid, Microsoft.Windows.Controls.DataGridCellInfo cellInfo) { Microsoft.Windows.Controls.DataGridCell result = null; Microsoft.Windows.Controls.DataGridRow row = null; try { grid.ScrollIntoView(cellInfo.Item); grid.UpdateLayout(); row = (Microsoft.Windows.Controls.DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(cellInfo.Item); if (row != null) { int columnIndex = grid.Columns.IndexOf(cellInfo.Column); if (columnIndex > -1) { Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter presenter = GetVisualChild <Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter>(row); result = presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex) as Microsoft.Windows.Controls.DataGridCell; } } } catch (Exception generalException) { string error = generalException.Message; result = null; } return(result); }
public static Microsoft.Windows.Controls.DataGridCell GetCell(Microsoft.Windows.Controls.DataGrid dataGrid, Microsoft.Windows.Controls.DataGridRow rowContainer, int column) { if (rowContainer != null) { DataGridCellsPresenter presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer); if (presenter == null) { /* if the row has been virtualized away, call its ApplyTemplate() method * to build its visual tree in order for the DataGridCellsPresenter * and the DataGridCells to be created */ rowContainer.ApplyTemplate(); presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer); } if (presenter != null) { Microsoft.Windows.Controls.DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as Microsoft.Windows.Controls.DataGridCell; if (cell == null) { /* bring the column into view * in case it has been virtualized away */ dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]); cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as Microsoft.Windows.Controls.DataGridCell; } return(cell); } } return(null); }
private void DataGridCell_PreviewTextInput(object sender, TextCompositionEventArgs e) { DataGridCell cell = sender as DataGridCell; if (cell != null) { GridColumnFastEdit(cell, e); } else { Microsoft.Windows.Controls.DataGridCell toolkitcell = sender as Microsoft.Windows.Controls.DataGridCell; ToolkitGridColumnFastEdit(toolkitcell, e); } }
private void DataGridCell_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { DataGridCell cell = sender as DataGridCell; if (cell != null) { GridColumnFastEditOnFocus(cell, e); } else { Microsoft.Windows.Controls.DataGridCell toolkitcell = sender as Microsoft.Windows.Controls.DataGridCell; ToolkitGridColumnFastEditOnFocus(toolkitcell, e); } }
private void DataGridCell_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DataGridCell cell = sender as DataGridCell; if (cell != null) { GridColumnFastEdit(cell, e); } else { Microsoft.Windows.Controls.DataGridCell toolkitcell = sender as Microsoft.Windows.Controls.DataGridCell; ToolkitGridColumnFastEdit(toolkitcell, e); } }
protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) { if (editingEventArgs == null) { return(null); } Microsoft.Windows.Controls.DataGridCell cell = editingEventArgs.Source as Microsoft.Windows.Controls.DataGridCell; if (cell != null) { // Changed to support EF POCOs PropertyInfo info = editingElement.DataContext.GetType().GetProperty(CustComboBoxSelectedValue, BindingFlags.Public | BindingFlags.Instance); object obj = info.GetValue(editingElement.DataContext, null); comboBox.SelectedValue = obj; } return(comboBox.SelectedItem); }
/// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(Microsoft.Windows.Controls.DataGridCell cell, object dataItem) { if (comboBox.Columns.Count == 0) { //Add columns to DataGrid columns for (int i = 0; i < columns.Count; i++) { comboBox.Columns.Add(columns[i]); } } //var comboBox = (ComboBox)base.GenerateEditingElement(cell, dataItem); //comboBox.SelectionChanged += ComboBox_SelectionChanged; comboBox.IsDropDownOpen = true; return(comboBox); }
private void ToolkitDataGrid_PreviewKeyDown(object sender, KeyEventArgs e) { Microsoft.Windows.Controls.DataGrid dataGrid = sender as Microsoft.Windows.Controls.DataGrid; if (dataGrid == null) { return; } if (e.Key == Key.Enter || e.Key == Key.Tab || e.Key == Key.Down || e.Key == Key.Up || e.Key == Key.Right || e.Key == Key.Left) { if (dataGrid.ItemsSource != null && dataGrid.SelectedIndex == dataGrid.Items.Count - 2) { var border = VisualTreeHelper.GetChild(dataGrid, 0) as Decorator; if (border != null) { var scroll = border.Child as ScrollViewer; if (scroll != null) { scroll.ScrollToEnd(); } } } } if (e.Key == Key.Enter || e.Key == Key.Tab) { TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next); request.Wrapped = true; Microsoft.Windows.Controls.DataGridRow rowContainer = (Microsoft.Windows.Controls.DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.CurrentItem); if (rowContainer != null) { int columnIndex = dataGrid.Columns.IndexOf(dataGrid.CurrentColumn); Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter presenter = GetVisualChild <Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter>(rowContainer); dataGrid.CommitEdit(); Microsoft.Windows.Controls.DataGridCell cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); cell.MoveFocus(request); dataGrid.SelectedItem = dataGrid.CurrentItem; e.Handled = true; dataGrid.UpdateLayout(); try { dataGrid.BeginEdit(e); } catch (System.InvalidOperationException) { //Ignore error if it is 'Recursive call to Automation Peer API is not valid.' } } } else if (e.Key == Key.Down || e.Key == Key.Up || e.Key == Key.Right || e.Key == Key.Left) { int columnIndex = dataGrid.Columns.IndexOf(dataGrid.CurrentColumn); Microsoft.Windows.Controls.DataGridRow rowContainer = (Microsoft.Windows.Controls.DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.CurrentItem); if (rowContainer != null) { Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter presenter = GetVisualChild <Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter>(rowContainer); Microsoft.Windows.Controls.DataGridCell currentcell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); if (currentcell.Content is ContentPresenter) { DatePickerCus datepicker = FindVisualChild <DatePickerCus>(currentcell); if (datepicker != null && datepicker.IsDropDownOpen) { e.Handled = true; return; } ComboBoxWithSearch combo = FindVisualChild <ComboBoxWithSearch>(currentcell); if (combo != null && combo.IsDropDownOpen) { e.Handled = true; return; } } if (e.Key == Key.Down) { dataGrid.CommitEdit(); dataGrid.SelectedIndex++; rowContainer = (Microsoft.Windows.Controls.DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.SelectedItem); if (rowContainer != null) { presenter = GetVisualChild <Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter>(rowContainer); Microsoft.Windows.Controls.DataGridCell cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); cell.Focus(); dataGrid.CurrentItem = dataGrid.SelectedItem; e.Handled = true; dataGrid.UpdateLayout(); try { dataGrid.BeginEdit(e); } catch (System.InvalidOperationException) { //Ignore error if it is 'Recursive call to Automation Peer API is not valid.' } } } else if (e.Key == Key.Up) { if (dataGrid.ItemsSource != null && dataGrid.SelectedIndex == 0) { return; } dataGrid.CommitEdit(); dataGrid.SelectedIndex--; rowContainer = (Microsoft.Windows.Controls.DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.SelectedItem); if (rowContainer != null) { presenter = GetVisualChild <Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter>(rowContainer); Microsoft.Windows.Controls.DataGridCell cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); cell.Focus(); dataGrid.CurrentItem = dataGrid.SelectedItem; e.Handled = true; dataGrid.UpdateLayout(); try { dataGrid.BeginEdit(e); } catch (System.InvalidOperationException) { //Ignore error if it is 'Recursive call to Automation Peer API is not valid.' } } } } } }
private static void ToolkitGridColumnFastEditOnFocus(Microsoft.Windows.Controls.DataGridCell cell, KeyboardFocusChangedEventArgs e) { if (cell == null || cell.IsEditing || cell.IsReadOnly) { return; } Microsoft.Windows.Controls.DataGrid dataGrid = FindVisualParent <Microsoft.Windows.Controls.DataGrid>(cell); if (dataGrid == null) { return; } dataGrid.UnselectAll(); if (dataGrid.SelectionUnit != Microsoft.Windows.Controls.DataGridSelectionUnit.FullRow) { if (!cell.IsSelected) { cell.IsSelected = true; } } else { Microsoft.Windows.Controls.DataGridRow row = FindVisualParent <Microsoft.Windows.Controls.DataGridRow>(cell); if (row != null && !row.IsSelected) { row.IsSelected = true; } } String statusmsg = ""; if (cell.Content is TextBlock) { TextBlock tb = cell.Content as TextBlock; if (tb != null) { statusmsg = tb.Text; } } else if (cell.Content is TextBox) { TextBox tb = cell.Content as TextBox; if (tb != null) { statusmsg = tb.Text; } } else if (cell.Content is ComboBox) { ComboBox cb = cell.Content as ComboBox; if (cb != null) { statusmsg = cb.Text; //DataGrid dataGrid = FindVisualParent<DataGrid>(cell); cell.Dispatcher.Invoke( DispatcherPriority.Background, new Action(delegate { })); cb.IsDropDownOpen = true; } } if (cell.Content is ContentPresenter) { TextBlock tb = FindVisualChild <TextBlock>(cell); if (tb != null) { statusmsg = tb.Text; } } StatusMessage.setStatus(statusmsg); }