public SimpleDataGridView(string table, bool HasFewColumns, int tipo) { ItemsSource = ResultsReader.GetResultsFromTable(table); if (tipo != 0) { if (string.IsNullOrEmpty(table)) { return; } IsReadOnly = false; if (HasFewColumns) { ColumnWidth = new GridViewLength(1, GridViewLengthUnitType.Star); } ClipboardCopyMode = GridViewClipboardCopyMode.Cells; SelectionUnit = GridViewSelectionUnit.Mixed; SelectionMode = SelectionMode.Extended; GroupPanelBackground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE6E6E6")); GroupPanelForeground = new SolidColorBrush(Colors.Black); FilteringMode = Telerik.Windows.Controls.GridView.FilteringMode.Popup; RowLoaded += BaseDataGrid_Formating; for (int i = 1; i < Columns.Count; i++) { GridViewDataColumn column = Columns[i] as GridViewDataColumn; column.ShowFieldFilters = false; column.ShowFilterButton = false; System.Type Tipo = column.DataType; bool Valor; Valor = Tipo.IsValueType; if (Valor) { if (column.Header.ToString().ToLower() == "escenario" || column.Header.ToString().ToLower() == "bloque" || column.Header.ToString().ToLower() == "periodo") { column.DataFormatString = "{0:F0}"; } else { column.DataFormatString = "{0:F2}"; } } } GridViewDataColumn textBoxColumn = new GridViewDataColumn(); textBoxColumn = new GridViewDataColumn { Name = "FechaPeriodo", Header = "Fecha", IsAutoGenerated = true, Width = 80 }; } }
/// <summary> /// create RadDocument from the DataGrid /// </summary> /// <returns>Returns the RadDcoument for the Grid</returns> public override DCFPDFExport CreateDocument() { try { DCFPDFExport data = new DCFPDFExport(); GridViewLength columnWidth = this.dgDCFSummary.Columns[0].ActualWidth; data.DataTable = PDFExporter.CreateTable(dgDCFSummary, 12, columnWidth, string.Empty); return(data); } catch (Exception ex) { Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + Logging.StackTraceToString(ex), "Exception", MessageBoxButton.OK); Logging.LogException(this.DataContextSource.Logger, ex); return(null); } }
public BaseDataGridView(EntitiesCollections entitiesCollections) { //DataTable dataTable; // Width = 0.5; AutoGenerateColumns = false; IsReadOnly = false; CanUserInsertRows = true; //ColumnWidth = new GridViewLength(1, GridViewLengthUnitType.Star); // MessageBox.Show("Culture despues:", Thread.CurrentThread.CurrentCulture.ToString()); // GridViewImageColumn. ColumnWidth = new GridViewLength(.5, GridViewLengthUnitType.Auto); GroupRenderMode = GroupRenderMode.Flat; NewRowPosition = GridViewNewRowPosition.Bottom; ClipboardCopyMode = GridViewClipboardCopyMode.Cells; ClipboardPasteMode = GridViewClipboardPasteMode.Default; SelectionUnit = GridViewSelectionUnit.Mixed; SelectionMode = SelectionMode.Extended; FilteringMode = Telerik.Windows.Controls.GridView.FilteringMode.Popup; GroupPanelBackground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE6E6E6")); GroupPanelForeground = new SolidColorBrush(Colors.Black); Pasting += BaseDataGrid_Pasting; RowLoaded += BaseDataGrid_Formating; //RowLoaded += dataGridView1_CellFormatting; // this.BaseDataGrid_Formating += new RowFormattingEventHandler(radGridView1_RowFormatting); Binding binding = new Binding(); binding.Source = entitiesCollections; binding.BindsDirectlyToSource = true; //binding.ConverterCulture = new System.Globalization.CultureInfo("en-US"); //binding.ConverterCulture.NumberFormat.NumberDecimalSeparator = "."; SetBinding(DataContextProperty, binding); }
/// <summary> /// create RadDocument from the DataGrid /// </summary> /// <returns>Returns the RadDcoument for the Grid</returns> public override DCFPDFExport CreateDocument() { try { DCFPDFExport data = new DCFPDFExport(); GridViewLength columnWidth = this.dgDCFAnalysisSummary.Columns[0].ActualWidth; data.DataTable = PDFExporter.CreateTable(dgDCFAnalysisSummary, 12, columnWidth, string.Empty); data.CountryName = this.DataContextSource.CountryName; data.SecurityName = this.DataContextSource.EntitySelectionData.ShortName; data.CreatedBy = SessionManager.SESSION.UserName; foreach (GridViewBoundColumnBase item in dgDCFAnalysisSummary.Columns) { item.Width = GridViewLength.Auto; } return(data); } catch (Exception ex) { Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + Logging.StackTraceToString(ex), "Exception", MessageBoxButton.OK); Logging.LogException(this.DataContextSource.Logger, ex); return(null); } }
/// <summary> /// create RadDocument from the DataGrid /// </summary> /// <returns>Returns the RadDcoument for the Grid</returns> public override DCFPDFExport CreateDocument() { try { if (dgTerminalValueCalculations.Items.Count > 0) { DCFPDFExport data = new DCFPDFExport(); GridViewLength columnWidth = this.dgTerminalValueCalculations.Columns[0].ActualWidth; data.DataTable = PDFExporter.CreateTable(dgTerminalValueCalculations, 12, columnWidth, "Terminal Value"); return(data); } else { return(null); } } catch (Exception ex) { Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + Logging.StackTraceToString(ex), "Exception", MessageBoxButton.OK); Logging.LogException(this.DataContextSource.Logger, ex); return(null); } }
/// <summary> /// Create Table /// </summary> /// <param name="grid">DataGrid</param> /// <param name="fontSize">FontSize</param> /// <param name="header">Header</param> /// <returns>Table</returns> public static Table CreateTable(RadGridView grid, int fontSize, GridViewLength width, string header = "" , Func <int, int, object, object, object> cellValueOverwrite = null) { List <GridViewBoundColumnBase> columns = (from c in grid.Columns.OfType <GridViewBoundColumnBase>() orderby c.DisplayIndex select c).ToList(); List <int> aggregateLog = new List <int>(); foreach (GridViewDataColumn column in grid.Columns) { if (column.AggregateFunctions.Count != 0) { aggregateLog.Add(column.DisplayIndex); } } List <int> visibleAggregateResultIndex = new List <int>(); for (int i = 0; i < aggregateLog.Count; i++) { if (grid.Columns[aggregateLog[i]].IsVisible) { visibleAggregateResultIndex.Add(i); } } if (width != null) { foreach (GridViewBoundColumnBase item in columns) { item.TextWrapping = TextWrapping.NoWrap; item.Width = 200; } } grid.InvalidateMeasure(); Table table = new Table(); fontSizePDF = fontSize; if (!String.IsNullOrEmpty(header)) { TableRow headerRow = new TableRow(); TableCell cell = new TableCell(); cell.Background = Color.FromArgb(255, 228, 229, 229); AddCellValue(cell, header); cell.ColumnSpan = columns.Count; headerRow.Cells.Add(cell); table.Rows.Add(headerRow); } //if (grid.ShowColumnHeaders) //{ TableRow colHeaderRow = new TableRow(); if (grid.GroupDescriptors.Count() > 0) { TableCell indentCell = new TableCell(); indentCell.PreferredWidth = new TableWidthUnit(grid.GroupDescriptors.Count() * 30); indentCell.Background = Colors.Gray; colHeaderRow.Cells.Add(indentCell); } for (int i = 0; i < columns.Count(); i++) { TableCell cell = new TableCell(); cell.Background = Color.FromArgb(255, 228, 229, 229); AddCellValue(cell, columns[i].UniqueName); cell.PreferredWidth = new TableWidthUnit((float)columns[i].ActualWidth); colHeaderRow.Cells.Add(cell); } table.Rows.Add(colHeaderRow); //} if (grid.Items.Groups != null) { for (int i = 0; i < grid.Items.Groups.Count(); i++) { AddGroupRow(table, grid.Items.Groups[i] as QueryableCollectionViewGroup, columns, grid, visibleAggregateResultIndex , cellValueOverwrite); } } else { AddDataRows(table, grid.Items, columns, grid, cellValueOverwrite); } return(table); }
private GridViewDataColumn AddPosition(string resourceKey, string member, string dataMember, GridViewLength width) { var fef = new FrameworkElementFactory(typeof(TextBlock)); var bindingText = new Binding(member); fef.SetBinding(TextBlock.TextProperty, bindingText); var template = new DataTemplate(); template.VisualTree = fef; template.Seal(); var column = new GridViewDataColumn { Header = CommonResourceManager.Instance.GetResourceString(resourceKey), DataMemberBinding = new Binding(dataMember), Width = width == 0 ? new GridViewLength(1, GridViewLengthUnitType.Star) : width, CellTemplate = template, UniqueName = member, }; return(column); }
private GridViewDataColumn GetMRatioColumn(string resourceKey, string member, GridViewLength width) { var fef = new FrameworkElementFactory(typeof(TextBlock)); var bindingText = new Binding(member); bindingText.Converter = new MRatioToTextConverter(); fef.SetBinding(TextBlock.TextProperty, bindingText); fef.SetValue(FrameworkElement.WidthProperty, 40.0); fef.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center); var rect = new FrameworkElementFactory(typeof(Rectangle)); rect.SetValue(FrameworkElement.WidthProperty, 20.0); var backgroundColorBinding = new Binding(member); backgroundColorBinding.Converter = new MRatioToColorConverter(); rect.SetBinding(Shape.FillProperty, backgroundColorBinding); var sp = new FrameworkElementFactory(typeof(StackPanel)); sp.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); sp.AppendChild(fef); sp.AppendChild(rect); var template = new DataTemplate { VisualTree = sp }; template.Seal(); var column = new GridViewDataColumn { Header = CommonResourceManager.Instance.GetResourceString(resourceKey), DataMemberBinding = new Binding(member), Width = width == 0 ? new GridViewLength(1, GridViewLengthUnitType.Star) : width, CellTemplate = template, UniqueName = member, }; return column; }