//Event for Microsoft.Windows.Controls.DataGrid popup MouseDown void popupDataGrid_MouseDown(object sender, MouseButtonEventArgs e) { Microsoft.Windows.Controls.DataGrid dg = sender as Microsoft.Windows.Controls.DataGrid; if (dg != null) { DependencyObject dep = (DependencyObject)e.OriginalSource; // iteratively traverse the visual tree and stop when dep is one of .. while ((dep != null) && !(dep is Microsoft.Windows.Controls.DataGridCell) && !(dep is DataGridColumnHeader)) { dep = VisualTreeHelper.GetParent(dep); } if (dep == null) { return; } if (dep is DataGridColumnHeader) { // do something } //When user clicks to Microsoft.Windows.Controls.DataGrid cell, popup have to be closed if (dep is Microsoft.Windows.Controls.DataGridCell) { this.IsDropDownOpen = false; } } }
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); }
/// <summary> /// Gets the cell. /// </summary> /// <param name="host">The host.</param> /// <param name="row">The row.</param> /// <param name="columnIndex">Index of the column.</param> /// <returns></returns> public static Microsoft.Windows.Controls.DataGridCell GetCell(Microsoft.Windows.Controls.DataGrid host, Microsoft.Windows.Controls.DataGridRow row, int columnIndex) { if (row == null) { return(null); } var presenter = GetVisualChild <DataGridCellsPresenter>(row); if (presenter == null) { return(null); } // try to get the cell but it may possibly be virtualized var cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); if (cell == null) { // now try to bring into view and retreive the cell host.ScrollIntoView(row, host.Columns[columnIndex]); cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex); } return(cell); }
private void dgUserList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Microsoft.Windows.Controls.DataGrid dgGrid = (Microsoft.Windows.Controls.DataGrid)sender; if (dgGrid.CurrentColumn.DisplayIndex != 1) { return; } try { FlowDocument flowDoc = new FlowDocument(); DependencyObject dep = (DependencyObject)e.OriginalSource; string strUserID = ((TextBlock)dep).Text; if (strUserID.Trim() == Login._UserInfo.Nickname.Trim()) { return; } Paragraph para = new Paragraph(); Run userID = new Run(strUserID + ", "); para.Inlines.Add(new Bold(userID)); flowDoc.Blocks.Add(para); rtxtMessageEdit.Document = flowDoc; rtxtMessageEdit.Focus(); } catch (System.Exception) { } }
//Synchronize selection between Combo and DataGrid popup void popupDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { //When open in Blend prevent raising exception if (!DesignerProperties.GetIsInDesignMode(this)) { Microsoft.Windows.Controls.DataGrid dg = sender as Microsoft.Windows.Controls.DataGrid; if (dg != null) { SelectedItem = dg.SelectedItem; SelectedValue = dg.SelectedValue; SelectedIndex = dg.SelectedIndex; SelectedValuePath = dg.SelectedValuePath; } } }
void CoreDataGrid_SizeChanged(object sender, SizeChangedEventArgs e) { DataGrid myDataGrid = (DataGrid)sender; // Do not change column size if Visibility State Changed if (myDataGrid.RenderSize.Width != 0) { double all_columns_sizes = 0.0; foreach (DataGridColumn column in myDataGrid.Columns) { all_columns_sizes += column.ActualWidth; } // Space available to fill ( -18 Standard vScrollbar) double space_available = (myDataGrid.RenderSize.Width - ScrollBarWidth) - all_columns_sizes; foreach (DataGridColumn column in myDataGrid.Columns) { column.Width = new DataGridLength(column.ActualWidth + (space_available / myDataGrid.Columns.Count)); } } }
public void ArrangeCargoToVehicle(DataGrid dataGrid1,TextBox textBox) { const int maxTonnage = 0; dataGrid1.CommitEdit(); if (containers.Count == 0) { MessageBox.Show("Нет груза для расчета."); } else if (selectedVehicles.Count == 0) MessageBox.Show("Не выбран автомобиль."); else { var wasteContainersList = calculation.CalculateLoadScheme(containers.Where(s => s.IsChecked).ToList(), selectedVehicles, textBox, maxTonnage); UpdateCheckProperty(wasteContainersList); } dataGrid1.ItemsSource = null; dataGrid1.ItemsSource = containers; //WriteLog("Выполнен расчет схемы загрузки контейнеров"); //SaveProtocolToFile(); }
//Apply theme and attach columns to DataGrid popupo control public override void OnApplyTemplate() { if (popupDataGrid == null) { popupDataGrid = this.Template.FindName(partPopupDataGrid, this) as Microsoft.Windows.Controls.DataGrid; if (popupDataGrid != null && columns != null) { //Add columns to DataGrid columns for (int i = 0; i < columns.Count; i++) { popupDataGrid.Columns.Add(columns[i]); } //Add event handler for DataGrid popup popupDataGrid.MouseDown += new MouseButtonEventHandler(popupDataGrid_MouseDown); popupDataGrid.SelectionChanged += new SelectionChangedEventHandler(popupDataGrid_SelectionChanged); } } //Call base class method base.OnApplyTemplate(); }
//Synchronize selection between Combo and DataGrid popup void popupDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { IstextChanged = true; //When open in Blend prevent raising exception if (!DesignerProperties.GetIsInDesignMode(this)) { Microsoft.Windows.Controls.DataGrid dg = sender as Microsoft.Windows.Controls.DataGrid; if (dg != null) { this.SelectedItem = dg.SelectedItem; //this.Text = ((System.Data.DataRowView)(dg.SelectedItem)).Row.ItemArray[1].ToString(); this.SelectedValue = dg.SelectedValue; this.SelectedIndex = dg.SelectedIndex; this.SelectedValuePath = dg.SelectedValuePath; } } if (!IsintextChanged) { IstextChanged = false; } }
private void AddDataGrid(StackPanel stackPanel, Microsoft.Windows.Controls.DataGrid dgGrid) { stackPanel.Children.Clear(); dgGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; dgGrid.Margin = new System.Windows.Thickness(1, 1, 0, 1); dgGrid.BorderBrush = new SolidColorBrush(Colors.Transparent); dgGrid.HeadersVisibility = Microsoft.Windows.Controls.DataGridHeadersVisibility.Column; dgGrid.GridLinesVisibility = Microsoft.Windows.Controls.DataGridGridLinesVisibility.Horizontal; dgGrid.RowHeaderWidth = 0; dgGrid.RowHeight = 18; dgGrid.Style = (Style)FindResource("DataGridStyle"); dgGrid.CellStyle = (Style)FindResource("dgCellStyle"); dgGrid.RowStyle = (Style)FindResource("dgRowStyle"); dgGrid.VerticalGridLinesBrush = (Brush)FindResource("TransparentGridLine"); dgGrid.HorizontalGridLinesBrush = (Brush)FindResource("TransparentGridLine"); dgGrid.Background = new SolidColorBrush(Color.FromRgb(251, 236, 166)); dgGrid.Foreground = new SolidColorBrush(Color.FromRgb(29, 56, 117)); dgGrid.FontSize = 11; dgGrid.IsReadOnly = true; dgGrid.SelectionMode = Microsoft.Windows.Controls.DataGridSelectionMode.Extended; dgGrid.SelectionUnit = Microsoft.Windows.Controls.DataGridSelectionUnit.FullRow; if (stackPanel.Name == "panUserList") { dgGrid.ColumnHeaderHeight = 0; dgGrid.HeadersVisibility = Microsoft.Windows.Controls.DataGridHeadersVisibility.None; } else { dgGrid.ColumnHeaderStyle = (Style)FindResource("dgColumnHeaderStyle"); } Microsoft.Windows.Controls.DataGridTemplateColumn col1 = new Microsoft.Windows.Controls.DataGridTemplateColumn(); col1.Header = " "; FrameworkElementFactory factory1 = new FrameworkElementFactory(typeof(Image)); System.Windows.Data.Binding b1 = new System.Windows.Data.Binding("face"); b1.Mode = BindingMode.TwoWay; factory1.SetValue(Image.SourceProperty, b1); DataTemplate cellTemplate1 = new DataTemplate(); cellTemplate1.VisualTree = factory1; col1.CellTemplate = cellTemplate1; col1.Width = 28; col1.MinWidth = 28; dgGrid.Columns.Add(col1); Microsoft.Windows.Controls.DataGridTextColumn col2 = new Microsoft.Windows.Controls.DataGridTextColumn(); col2.Header = "用户名"; col2.Width = 90; col2.MinWidth = 90; col2.Binding = new System.Windows.Data.Binding("id"); dgGrid.Columns.Add(col2); Microsoft.Windows.Controls.DataGridTextColumn col3 = new Microsoft.Windows.Controls.DataGridTextColumn(); col3.Header = "押注金额"; col3.Width = 45;// Microsoft.Windows.Controls.DataGridLength.Auto; col3.MinWidth = 45; col3.Binding = new System.Windows.Data.Binding("betscore"); col3.ElementStyle = (Style)FindResource("dgElementRightStyle"); dgGrid.Columns.Add(col3); Microsoft.Windows.Controls.DataGridTextColumn col4 = new Microsoft.Windows.Controls.DataGridTextColumn(); col4.Header = " 金额"; col4.Width = 50;// Microsoft.Windows.Controls.DataGridLength.Auto; col4.MinWidth = 50; col4.Binding = new System.Windows.Data.Binding("score"); col4.ElementStyle = (Style)FindResource("dgElementRightStyle"); dgGrid.Columns.Add(col4); Microsoft.Windows.Controls.DataGridTextColumn col5 = new Microsoft.Windows.Controls.DataGridTextColumn(); col5.Header = ""; col5.Width = 25; dgGrid.Columns.Add(col5); dgGrid.Items.Clear(); stackPanel.Children.Add(dgGrid); }
//Apply theme and attach columns to DataGrid popupo control public override void OnApplyTemplate() { if (GetFeatureID(this) == 0) return; if (popupDataGrid == null) { popupDataGrid = this.Template.FindName("PART_PopupDataGrid", this) as Microsoft.Windows.Controls.DataGrid; popupDataGrid.GridLinesVisibility = Microsoft.Windows.Controls.DataGridGridLinesVisibility.None; Style ColumnHeaderStyle = new System.Windows.Style(); ColumnHeaderStyle.Setters.Add(new Setter() { Property = FontSizeProperty, Value = Convert.ToDouble(12) }); ColumnHeaderStyle.Setters.Add(new Setter() { Property = FontWeightProperty, Value = FontWeights.Bold }); ColumnHeaderStyle.Setters.Add(new Setter() { Property = BackgroundProperty, Value = Brushes.SteelBlue}); ColumnHeaderStyle.Setters.Add(new Setter() { Property = ForegroundProperty, Value = Brushes.White }); popupDataGrid.ColumnHeaderStyle = ColumnHeaderStyle; if (popupDataGrid != null) { for (int i = 0; i < columns.Count; i++) popupDataGrid.Columns.Add(columns[i]); popupDataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; SetSearchColumn(1, true); popupDataGrid.ItemsSource = this.ItemsSource; //Add event handler for DataGrid popup popupDataGrid.MouseUp += new MouseButtonEventHandler(popupDataGrid_MouseDown); popupDataGrid.SelectionChanged += new SelectionChangedEventHandler(popupDataGrid_SelectionChanged); } } //Call base class method base.OnApplyTemplate(); if (txt == null) { txt = this.Template.FindName("PART_EditableTextBox", this) as TextBox; if (txt != null) { txt.TextChanged += new TextChangedEventHandler(txt_TextChanged); } } }
public bool HourlyExportToExcel(Microsoft.Windows.Controls.DataGrid lvView, string path, bool isFromMainScreen) { try { LogManager.WriteLog("Process started - 1", LogManager.enumLogLevel.Info); Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application(); StreamWriter sw = new StreamWriter(path); Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet); Worksheet ws = (Worksheet)xla.ActiveSheet; LogManager.WriteLog("Process started - 2", LogManager.enumLogLevel.Info); int i = 1; int j = 1; Microsoft.Windows.Controls.DataGrid gridView = lvView; string mystr = string.Empty; int sum = -1; foreach (Microsoft.Windows.Controls.DataGridColumn dc in gridView.Columns) { ++sum; if (isFromMainScreen && (sum == 1 || sum == 3 || sum == 4)) { continue; } else if (!isFromMainScreen && (sum == 0 || sum == 2)) { continue; } string mynewstr = string.Format("\"{0}\"", dc.Header.ToString() + ""); mystr += mynewstr + ","; } mystr += "\r\n"; //int Count = -1; foreach (HourlyDetailEntity item in lvView.Items) { if (isFromMainScreen) { mystr += string.Format("\"{0}\",", Convert.ToString(item.Date.GetUniversalDateFormat()) + ""); mystr += string.Format("\"{0}\",", Convert.ToString(item.Day) + ""); //if (item.Total == 0.0) //{ // mystr += string.Format("\"{0}\",", "-" + ""); //} // else // { // } } else if (!isFromMainScreen) { mystr += string.Format("\"{0}\",", Convert.ToString(item.Bar_Position_Name) + ""); //++Count; //if (Count == 0) // mystr += string.Format("\"{0}\",", "Total"); //else // mystr += string.Format("\"{0}\",", Count); mystr += string.Format("\"{0}\",", Convert.ToString(item.Machine_Name) + ""); mystr += string.Format("\"{0}\",", Convert.ToString(item.Stock_No) + ""); } //mystr += string.Format("\"{0}\",", Convert.ToString(item.Stock_No) + ""); //} mystr += Format(item.Total); //string.Format("\"{0}\",", Convert.ToString(item.Total) + ""); mystr += Format(item.HS_Hour1_Value); mystr += Format(item.HS_Hour2_Value); mystr += Format(item.HS_Hour3_Value); mystr += Format(item.HS_Hour4_Value); mystr += Format(item.HS_Hour5_Value); mystr += Format(item.HS_Hour6_Value); mystr += Format(item.HS_Hour7_Value); mystr += Format(item.HS_Hour8_Value); mystr += Format(item.HS_Hour9_Value); mystr += Format(item.HS_Hour10_Value); mystr += Format(item.HS_Hour11_Value); mystr += Format(item.HS_Hour12_Value); mystr += Format(item.HS_Hour13_Value); mystr += Format(item.HS_Hour14_Value); mystr += Format(item.HS_Hour15_Value); mystr += Format(item.HS_Hour16_Value); mystr += Format(item.HS_Hour17_Value); mystr += Format(item.HS_Hour18_Value); mystr += Format(item.HS_Hour19_Value); mystr += Format(item.HS_Hour20_Value); mystr += Format(item.HS_Hour21_Value); mystr += Format(item.HS_Hour22_Value); mystr += Format(item.HS_Hour23_Value); mystr += Format(item.HS_Hour24_Value); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour1_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour2_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour3_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour4_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour5_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour6_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour7_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour8_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour9_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour10_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour11_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour12_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour13_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour14_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour15_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour16_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour17_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour18_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour19_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour20_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour21_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour22_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour23_Value) + ""); //mystr += string.Format("\"{0}\",", Convert.ToString(item.HS_Hour24_Value) + ""); mystr += "\r\n"; } mystr += "\r\n"; sw.Write(mystr); mystr = string.Empty; sw.Close(); return(true); } catch (Exception ex) { ExceptionManager.Publish(ex); return(false); } }
//Apply theme and attach columns to DataGrid popupo control public override void OnApplyTemplate() { if (GetFeatureID(this) == 0) { return; } if (popupDataGrid == null) { popupDataGrid = this.Template.FindName("PART_PopupDataGrid", this) as Microsoft.Windows.Controls.DataGrid; popupDataGrid.GridLinesVisibility = Microsoft.Windows.Controls.DataGridGridLinesVisibility.None; Style ColumnHeaderStyle = new System.Windows.Style(); ColumnHeaderStyle.Setters.Add(new Setter() { Property = FontSizeProperty, Value = Convert.ToDouble(12) }); ColumnHeaderStyle.Setters.Add(new Setter() { Property = FontWeightProperty, Value = FontWeights.Bold }); ColumnHeaderStyle.Setters.Add(new Setter() { Property = BackgroundProperty, Value = Brushes.SteelBlue }); ColumnHeaderStyle.Setters.Add(new Setter() { Property = ForegroundProperty, Value = Brushes.White }); popupDataGrid.ColumnHeaderStyle = ColumnHeaderStyle; if (popupDataGrid != null) { for (int i = 0; i < columns.Count; i++) { popupDataGrid.Columns.Add(columns[i]); } popupDataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; SetSearchColumn(1, true); popupDataGrid.ItemsSource = this.ItemsSource; //Add event handler for DataGrid popup popupDataGrid.MouseUp += new MouseButtonEventHandler(popupDataGrid_MouseDown); popupDataGrid.SelectionChanged += new SelectionChangedEventHandler(popupDataGrid_SelectionChanged); } } //Call base class method base.OnApplyTemplate(); if (txt == null) { txt = this.Template.FindName("PART_EditableTextBox", this) as TextBox; if (txt != null) { txt.TextChanged += new TextChangedEventHandler(txt_TextChanged); } } }
public bool HourlyExportToExcel(Microsoft.Windows.Controls.DataGrid lvView, string path, bool IsMainScreen) { return(objCommon.HourlyExportToExcel(lvView, path, IsMainScreen)); }
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 void getdata() { TreasuryTransactions objTT = new TreasuryTransactions(); List<rsp_CDM_GetCashierTransactionsDetails_New> detailslist = objTT.rsp_CDM_GetCashierTransactionsDetails_New(StartDate, EndDate, UserNo, iRoute_No, chkCashDeskTicketIn.IsChecked.Value, chkCashDeskTicketOut.IsChecked.Value, chkHandpays.IsChecked.Value, chkShortPays.IsChecked.Value, chkVoidVoucher.IsChecked.Value, chkjackpot.IsChecked.Value, chkProghandpays.IsChecked.Value, chkVoidTransactions.IsChecked.Value, chkTicketIn.IsChecked.Value, chkTicketOut.IsChecked.Value, chkActive.IsChecked.Value, chkVoidCancel.IsChecked.Value, chkExpired.IsChecked.Value, chkException.IsChecked.Value, chkLiability.IsChecked.Value, false, chkNCTicketIn.IsChecked.Value, chkNCTicketOut.IsChecked.Value, chkOfflinevoucher.IsChecked.Value, chkUnprocessedHandpay.IsChecked.Value ); string sFooter = GetFooterText(); var objViewAll = new CashDeskManagerAllDetails(detailslist, StartDate, EndDate, sFooter, UserNo, iRoute_No); objViewAll.btnExit.Click += ObjPosDetailsExitClicked; objViewAll.Owner = MessageBox.parentOwner; // pnlContent.Children.Add(objViewAll); objViewAll.ShowDialogEx(this); lvView = objViewAll.lvViewAll; }
public void OnCellEditEnding(object sender, Microsoft.Windows.Controls.DataGridCellEditEndingEventArgs e) { try { TextBox tb = e.EditingElement as TextBox; Microsoft.Windows.Controls.DataGrid dg = sender as Microsoft.Windows.Controls.DataGrid; string column = e.Column.SortMemberPath; if (ProductWeightSelectedItem != null) { if (column == "SIGN") { if (!(tb.Text == "-" || tb.Text == "+")) { tb.Undo(); } } ProductWeightSelectedItem.BeginEdit(); if (column == "VAL1" || column == "VAL2" || column == "VAL3" || column == "SIGN") { ProductWeightSelectedItem[column] = tb.Text; } double pvVAL1 = 0, pvVAL2 = 0, pvVAL3 = 0; if ((column == "VAL1" || column == "VAL1" || column == "VAL1" || column == "VOLUME") || ProductWeightSelectedItem["SHAPE_CODE"].ToString() != "") { 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 (ProductWeightSelectedItem["SHAPE_CODE"].ToString() == "DH" && (pvVAL1 > 0 || pvVAL2 > 0) && pvVAL1 == pvVAL2) { MessageBox.Show("Dimension-II Value should not be equals to Dimension-I value.", ApplicationTitle, MessageBoxButton.OK, MessageBoxImage.Information); pvVAL2 = 0; ProductWeightSelectedItem["VAL2"] = 0; ProductWeightSelectedItem["VOLUME"] = 0; } if (ProductWeightSelectedItem["SHAPE_CODE"].ToString() == "DH" && pvVAL2 > pvVAL1) { MessageBox.Show("Dimension-II Value should not be greater than Dimension-I value.", ApplicationTitle, MessageBoxButton.OK, MessageBoxImage.Information); pvVAL2 = 0; ProductWeightSelectedItem["VAL2"] = 0; ProductWeightSelectedItem["VOLUME"] = 0; } 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(); } }
public static void BindDataGrid(DataTable table, Microsoft.Windows.Controls.DataGrid dataGrid) { System.Windows.Data.Binding bind = new System.Windows.Data.Binding(); bind.Source = table; dataGrid.SetBinding(Microsoft.Windows.Controls.DataGrid.ItemsSourceProperty, bind); }
public static void BindDataGrid <T>(IEnumerable <T> template, Microsoft.Windows.Controls.DataGrid dataGrid) { System.Windows.Data.Binding bind = new System.Windows.Data.Binding(); bind.Source = template; dataGrid.SetBinding(Microsoft.Windows.Controls.DataGrid.ItemsSourceProperty, bind); }
void dataGrid1_RowDetailsVisibilityChanged(object sender, Microsoft.Windows.Controls.DataGridRowDetailsEventArgs e) { Microsoft.Windows.Controls.DataGrid innerDataGrid = e.DetailsElement as Microsoft.Windows.Controls.DataGrid; innerDataGrid.ItemsSource = ((IListSource)dt).GetList(); }
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); }