public void WeightCalc_CurrentCellChanged(object sender, EventArgs e) { try { Microsoft.Windows.Controls.DataGridCellInfo cell = ((Microsoft.Windows.Controls.DataGrid)(sender)).CurrentCell; if (ProductWeightSelectedItem != null && cell.Column != null) { string column = cell.Column.SortMemberPath; ProductWeightSelectedItem.BeginEdit(); double pvVAL1 = 0, pvVAL2 = 0, pvVAL3 = 0; if (ProductWeightSelectedItem["VAL1"].ToString() != "") { pvVAL1 = Convert.ToDouble(ProductWeightSelectedItem["VAL1"]); } if (ProductWeightSelectedItem["VAL2"].ToString() != "") { pvVAL2 = Convert.ToDouble(ProductWeightSelectedItem["VAL2"]); } if (ProductWeightSelectedItem["VAL3"].ToString() != "") { pvVAL3 = Convert.ToDouble(ProductWeightSelectedItem["VAL3"]); } if (pvVAL1 != 0 && pvVAL2 != 0) { ProductWeightSelectedItem["VOLUME"] = VolumeCalculation(ProductWeightSelectedItem["SHAPE_CODE"].ToString(), pvVAL1, pvVAL2, pvVAL3); } else { ProductWeightSelectedItem["VOLUME"] = 0; } if (ProductWeightSelectedItem["SIGN"].ToString() == "-") { ProductWeightSelectedItem["VOLUME"] = 0 - Math.Abs(Convert.ToDouble(ProductWeightSelectedItem["VOLUME"])); } else { ProductWeightSelectedItem["VOLUME"] = Math.Abs(Convert.ToDouble(ProductWeightSelectedItem["VOLUME"])); } ProductWeightSelectedItem.EndEdit(); if (column == "SHAPE_CODE" && ProductWeightSelectedItem["SHAPE_CODE"].ToString() != "") { if (ProductWeight.DVShapeDetails[ProductWeight.DVShapeDetails.Count - 1]["SHAPE_CODE"].ToString() != "") { ProductWeight.DVShapeDetails.AddNew(); } } } } catch (Exception ex) { throw ex.LogException(); } }
void CaseDataAddMenuitem_Click(object sender, RoutedEventArgs e) { try { MenuItem menuitem = sender as MenuItem; if (!_chatUtil.UserData.ContainsKey(menuitem.Header.ToString())) { _chatUtil.UserData.Add(menuitem.Header.ToString(), string.Empty); } if (_chatUtil.NotifyCaseData.Count(p => p.Key == menuitem.Header.ToString()) == 0) { _chatUtil.NotifyCaseData.Add(new ChatCaseData(menuitem.Header.ToString(), string.Empty)); } BindGrid(); _caseDataAdd.Items.Remove(menuitem); DGCaseDataInfo.UpdateLayout(); if (DGCaseDataInfo.Items.Count > 2) { DGCaseDataInfo.ScrollIntoView(DGCaseDataInfo.Items[DGCaseDataInfo.Items.Count - 2]); } int rowIndex = _chatUtil.NotifyCaseData.IndexOf(_chatUtil.NotifyCaseData.Where(p => p.Key == menuitem.Header.ToString()).FirstOrDefault()); var dataGridCellInfo = new Microsoft.Windows.Controls.DataGridCellInfo(DGCaseDataInfo.Items[rowIndex], DGCaseDataInfo.Columns[1]); var cell = TryToFindGridCell(DGCaseDataInfo, dataGridCellInfo); if (cell == null) { return; } cell.Focus(); DGCaseDataInfo.BeginEdit(); } catch (Exception commonException) { _logger.Error("Error occurred as : " + commonException.Message.ToString()); } }
/// <summary> /// Handles the Click event of the CaseDataAddMenuitem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> void CaseDataAddMenuitem_Click(object sender, RoutedEventArgs e) { try { MenuItem menuitem = sender as MenuItem; //DGCaseDataInfo.UpdateLayout(); emailDetails.EmailCaseData.Add(new EmailCaseData() { Key = menuitem.Header.ToString(), Value = string.Empty }); if (!CurrentData.ContainsKey(menuitem.Header.ToString())) { CurrentData.Add(menuitem.Header.ToString(), ""); } DGCaseDataInfo.UpdateLayout(); //BindGrid(); if (DGCaseDataInfo.Items.Count > 2) { DGCaseDataInfo.ScrollIntoView(DGCaseDataInfo.Items[DGCaseDataInfo.Items.Count - 2]); } int rowIndex = emailDetails.EmailCaseData.IndexOf(emailDetails.EmailCaseData.Where(x => x.Key.Equals(menuitem.Header.ToString())).SingleOrDefault()); var dataGridCellInfo = new Microsoft.Windows.Controls.DataGridCellInfo(DGCaseDataInfo.Items[rowIndex], DGCaseDataInfo.Columns[1]); var cell = TryToFindGridCell(DGCaseDataInfo, dataGridCellInfo); if (cell == null) { return; } cell.Focus(); DGCaseDataInfo.BeginEdit(); _caseDataAdd.Items.Remove(menuitem); editingKey = menuitem.Header.ToString(); editingValue = string.Empty; if (_caseDataAdd.Items.Count == 0) { // Addded by sakthi to hide, if there is no item available to add after added all item. // Date : 20-02-2016 btnAddCaseData.Visibility = Visibility.Collapsed; } } catch (Exception commonException) { logger.Error("Error occurred as : " + commonException.Message.ToString()); } }
/// <summary> /// Handles the Click event of the CallDataAddMenuitem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> public void CallDataAddMenuitem1_Click(object sender, RoutedEventArgs e) { try { MenuItem menuitem = sender as MenuItem; DGAttachData.UpdateLayout(); if (DGAttachData.Items.Count > 2) { DGAttachData.ScrollIntoView(DGAttachData.Items[DGAttachData.Items.Count - 2]); } int rowIndex = Datacontext.GetInstance() .NotifyCallData.IndexOf( Datacontext.GetInstance() .NotifyCallData.Where(p => p.Key == menuitem.Header.ToString()) .FirstOrDefault()); var dataGridCellInfo = new Microsoft.Windows.Controls.DataGridCellInfo(DGAttachData.Items[rowIndex], DGAttachData.Columns[1]); var cell = TryToFindGridCell(DGAttachData, dataGridCellInfo); if (cell == null) { return; } cell.Focus(); _isCaseDataManualBeginEdit = true; DGAttachData.BeginEdit(); if (_dataContext.NotifyCallData.Count <= 0) { DGAttachData.Visibility = Visibility.Collapsed; txtAttachDataInfo.Visibility = Visibility.Visible; } else { DGAttachData.Visibility = Visibility.Visible; txtAttachDataInfo.Visibility = Visibility.Collapsed; } } catch (Exception commonException) { _logger.Error("CallDataAddMenuitem_Click: " + commonException.Message.ToString()); } }
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) { } }
/// <summary> /// Tries to find grid cell. /// </summary> /// <param name="grid">The grid.</param> /// <param name="cellInfo">The cell information.</param> /// <returns>Microsoft.Windows.Controls.DataGridCell.</returns> 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; 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; } } return(result); }
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; // } // }; //}; }