private void ResizeGridViewColumn(Microsoft.Windows.Controls.DataGridColumn column) { if (double.IsNaN(column.Width.DisplayValue)) { column.Width = new Microsoft.Windows.Controls.DataGridLength(column.ActualWidth); } // column.Width = new Microsoft.Windows.Controls.DataGridLength(double.NaN); }
private void ssCostDetails_PreviewKeyDown(object sender, KeyEventArgs e) { try { int columnDisplayIndex = ssCostDetails.CurrentCell.Column.DisplayIndex; if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) || e.Key == Key.Left) { e.Handled = true; if (columnDisplayIndex == 0) { ssCostDetails.SelectedIndex = ssCostDetails.SelectedIndex - 1; columnDisplayIndex = ssCostDetails.Columns.Count - 1; } else { if (columnDisplayIndex == 1) { columnDisplayIndex = 0; } else { columnDisplayIndex = columnDisplayIndex - 1; } } Microsoft.Windows.Controls.DataGridColumn nextColumn = ssCostDetails.ColumnFromDisplayIndex(columnDisplayIndex); // now telling the grid, that we handled the key down event //e.Handled = true; // setting the current cell (selected, focused) ssCostDetails.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(ssCostDetails.SelectedItem, nextColumn); // tell the grid to initialize edit mode for the current cell ssCostDetails.BeginEdit(); } else { if (e.Key == Key.Tab || e.Key == Key.Right) { if (columnDisplayIndex == 8) { columnDisplayIndex = 0; ssCostDetails.SelectedIndex = ssCostDetails.SelectedIndex + 1; } else { columnDisplayIndex = columnDisplayIndex + 1; } int selectedIndex = 0; selectedIndex = ssCostDetails.SelectedIndex; Microsoft.Windows.Controls.DataGridColumn nextColumn = ssCostDetails.ColumnFromDisplayIndex(columnDisplayIndex); // now telling the grid, that we handled the key down event e.Handled = true; // setting the current cell (selected, focused) ssCostDetails.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(ssCostDetails.SelectedItem, nextColumn); ssCostDetails.ScrollIntoView(ssCostDetails.CurrentCell); // tell the grid to initialize edit mode for the current cell ssCostDetails.BeginEdit(); } } } catch (Exception ex) { } //try //{ // if ((e.Key == Key.Tab && !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))) || e.Key == Key.Enter) // { // int columnDisplayIndex = 0; // Microsoft.Windows.Controls.DataGrid grid = (Microsoft.Windows.Controls.DataGrid)sender; // //grid.SelectedIndex = 0; // // get the selected row // var selectedRow = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as Microsoft.Windows.Controls.DataGridRow; // // selectedRow can be null due to virtualization // if (selectedRow != null) // { // // there should always be a selected cell // if (grid.SelectedCells.Count != 0) // { // columnDisplayIndex = grid.CurrentCell.Column.DisplayIndex; // if (columnDisplayIndex == 0) // { // columnDisplayIndex = 1; // } // DataRowView drv = (DataRowView)grid.SelectedItem; // if (!(drv["SNO"]).ToString().IsNotNullOrEmpty()) // { // columnDisplayIndex = 0; // } // if (((drv["SNO"]).ToString().IsNotNullOrEmpty()) && !((drv["OPERATION_NO"]).ToString().IsNotNullOrEmpty())) // { // columnDisplayIndex = 0; // } // if (columnDisplayIndex < grid.Columns.Count) // { // // get the DataGridColumn instance from the display index // Microsoft.Windows.Controls.DataGridColumn nextColumn = grid.ColumnFromDisplayIndex(columnDisplayIndex); // // now telling the grid, that we handled the key down event // //e.Handled = true; // // setting the current cell (selected, focused) // grid.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(grid.SelectedItem, nextColumn); // // tell the grid to initialize edit mode for the current cell // grid.BeginEdit(); // } // } // } // } //} //catch (Exception ex) //{ // ex.LogException(); //} }
private void dgvPccs_PreviewKeyDown(object sender, KeyEventArgs e) { try { int columnDisplayIndex = dgvPccs.CurrentCell.Column.DisplayIndex; //if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)) //original if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) || e.Key == Key.Left) { if (e.Key == Key.Left) { try { Microsoft.Windows.Controls.DataGridCellInfo dgt = dgvPccs.CurrentCell; var cellContent = dgt.Column.GetCellContent(dgt.Item); //cellContent.SelectionLength //if (cellContent != null) //{ // if (cellContent.SelectionLength != cellContent.Text.Length) // { // return; // } // //new by me // // TextBox // //end new by me //} } catch (Exception ex) { return; } } e.Handled = true; if (columnDisplayIndex == 0) { dgvPccs.SelectedIndex = dgvPccs.SelectedIndex - 1; columnDisplayIndex = dgvPccs.Columns.Count - 1; } else { if (columnDisplayIndex == 1) { columnDisplayIndex = 0; } //new by me else { columnDisplayIndex = columnDisplayIndex - 1; } //new by me } Microsoft.Windows.Controls.DataGridColumn nextColumn = dgvPccs.ColumnFromDisplayIndex(columnDisplayIndex); // now telling the grid, that we handled the key down event //e.Handled = true; // setting the current cell (selected, focused) dgvPccs.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(dgvPccs.SelectedItem, nextColumn); // tell the grid to initialize edit mode for the current cell dgvPccs.BeginEdit(); } else { //if (e.Key == Key.Tab || e.Key == Key.Right) if (e.Key == Key.Tab || (e.Key == Key.Right)) { //added by nandakumar if (e.Key == Key.Right) { try { Microsoft.Windows.Controls.DataGridCellInfo dgt = dgvPccs.CurrentCell; var cellContent = dgt.Column.GetCellContent(dgt.Item); //cellContent.SelectionLength //if (cellContent != null) //{ // if (cellContent != null) // { // return; // } // // TextBox //} } catch (Exception ex) { return; } } //end add by nandakumar //dgt.Column. //int columnDisplayIndex = dgvPccsRevisions.CurrentCell.Column.DisplayIndex; //if (dgvPccsRevisions.SelectedIndex == dgvPccsRevisions.Items.Count - 1) //{ // if (columnDisplayIndex == dgvPccsRevisions.Columns.Count - 1) // { // dgvPccsRevisions.Focus(); // } //} if (columnDisplayIndex == 14) { columnDisplayIndex = 0; dgvPccs.SelectedIndex = dgvPccs.SelectedIndex + 1; } else { columnDisplayIndex = columnDisplayIndex + 1; } int selectedIndex = 0; selectedIndex = dgvPccs.SelectedIndex; Microsoft.Windows.Controls.DataGridColumn nextColumn = dgvPccs.ColumnFromDisplayIndex(columnDisplayIndex); // now telling the grid, that we handled the key down event e.Handled = true; // setting the current cell (selected, focused) dgvPccs.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(dgvPccs.SelectedItem, nextColumn); dgvPccs.ScrollIntoView(dgvPccs.CurrentCell); // tell the grid to initialize edit mode for the current cell dgvPccs.BeginEdit(); } } } catch (Exception ex) { } }
public SalesEntry() { InitializeComponent(); RoutedEventHandler handler = null; handler = (object sender, RoutedEventArgs e) => { if (_salesViewModel.IsEditMode == false) { CboCustomers.SelectedValue = _salesViewModel.DefaultCustomer.Id; } Loaded -= handler; }; Loaded += handler; DataContextChanged += (sender, eventArgs) => { _salesViewModel = this.DataContext as SalesEntryViewModel; custComboBoxCol.ItemsSource = _salesViewModel.ProductsPriceList; custComboBoxCol.FilterPropertyName = "ProductName"; _salesViewModel.Extensions = SalesExtn.DataContext as IExtensions; }; SalesDataGrid.PreviewKeyUp += (s, e) => { if ((e.Key == Key.Enter) || (e.Key == Key.Return)) { var grid = s as Microsoft.Windows.Controls.DataGrid; //if (grid.CurrentColumn.Header.ToString().Equals("Barcode", StringComparison.OrdinalIgnoreCase)) //{ //if (grid.SelectionUnit == DataGridSelectionUnit.Cell || grid.SelectionUnit == DataGridSelectionUnit.CellOrRowHeader) //{ //var focusedElement = Keyboard.FocusedElement as UIElement; //focusedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left)); //grid.SelectedIndex = grid.SelectedIndex + 1; //grid.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left)); //} // get the selected row //var selectedRow = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow; //// selectedRow can be null due to virtualization //if (selectedRow != null) //{ // there should always be a selected cell if (grid.SelectedCells.Count != 0) { // get the cell info Microsoft.Windows.Controls.DataGridCellInfo currentCell = grid.SelectedCells[0]; // get the display index of the cell's column + 1 (for next column) int columnDisplayIndex = currentCell.Column.DisplayIndex; // if display index is valid if (columnDisplayIndex < grid.Columns.Count) { // get the DataGridColumn instance from the display index Microsoft.Windows.Controls.DataGridColumn nextColumn = grid.ColumnFromDisplayIndex(0); // now telling the grid, that we handled the key down event e.Handled = true; // setting the current cell (selected, focused) grid.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(grid.SelectedItem, nextColumn); // tell the grid to initialize edit mode for the current cell //grid.BeginEdit(); } } //grid.BeginEdit(); e.Handled = true; //} } }; //custComboBoxCol.comboBox.PreviewTextInput += ComboBox_PreviewTextInput; //custComboBoxCol.OnComboLoadedEvent += (txt) => //{ // custComboBoxCol._cboTextBox.PreviewKeyUp += (s, e) => // { // if (e.Key == System.Windows.Input.Key.Back && string.IsNullOrWhiteSpace(custComboBoxCol.comboBox.Text)) // { // custComboBoxCol.comboBox.ItemsSource = _salesViewModel.ProductsPriceList; // } // }; //}; }
private void ssDevReportLog_PreviewKeyDown(object sender, KeyEventArgs e) { try { int columnDisplayIndex = ssDevReportLog.CurrentCell.Column.DisplayIndex; //if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) || e.Key == Key.Left) if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)) { e.Handled = true; if (columnDisplayIndex == 2) { ssDevReportLog.SelectedIndex = ssDevReportLog.SelectedIndex - 1; columnDisplayIndex = ssDevReportLog.Columns.Count - 1; } else { if (columnDisplayIndex == 1) { columnDisplayIndex = 0; } else { columnDisplayIndex = columnDisplayIndex - 1; } } Microsoft.Windows.Controls.DataGridColumn nextColumn = ssDevReportLog.ColumnFromDisplayIndex(columnDisplayIndex); // now telling the grid, that we handled the key down event //e.Handled = true; // setting the current cell (selected, focused) ssDevReportLog.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(ssDevReportLog.SelectedItem, nextColumn); // tell the grid to initialize edit mode for the current cell ssDevReportLog.BeginEdit(); } else { //if (e.Key == Key.Tab || e.Key == Key.Right) if (e.Key == Key.Tab) { if (columnDisplayIndex == 7) { columnDisplayIndex = 2; ssDevReportLog.SelectedIndex = ssDevReportLog.SelectedIndex + 1; } else { columnDisplayIndex = columnDisplayIndex + 1; } int selectedIndex = 0; selectedIndex = ssDevReportLog.SelectedIndex; Microsoft.Windows.Controls.DataGridColumn nextColumn = ssDevReportLog.ColumnFromDisplayIndex(columnDisplayIndex); // now telling the grid, that we handled the key down event e.Handled = true; // setting the current cell (selected, focused) ssDevReportLog.CurrentCell = new Microsoft.Windows.Controls.DataGridCellInfo(ssDevReportLog.SelectedItem, nextColumn); ssDevReportLog.ScrollIntoView(ssDevReportLog.CurrentCell); // tell the grid to initialize edit mode for the current cell ssDevReportLog.BeginEdit(); } } } catch (Exception ex) { } }