// ******************************************************************* // common code for Column Auto-generation // i.e. creation of combo columns (we show the same data in all the grids) // ******************************************************************* public static void HandleColumnAutoGeneration(DataGridAutoGeneratingColumnEventArgs e) { if (new string[] { "Color", "ID", "ProductSubcategoryID", "Description", "GifImage" }.Contains(e.Property.Name)) { e.Cancel = true; return; } if (e.Property.Name == "ProductModelID") { var comboCol = new DataGridComboBoxColumn(e.Property); var models = Data.GetModels().OrderBy(m => m.Name).ToList(); models.Insert(0, new Model { Name = "Not specified", ProductModelID = 0 }); comboCol.ItemsSource = models; comboCol.DisplayMemberPath = "Name"; comboCol.SelectedValuePath = "ProductModelID"; comboCol.Header = "Model"; e.Column = comboCol; } if (e.Property.Name == "ImageUrl") { //CLR40 string imgPath = "/" + new AssemblyName(Assembly.GetExecutingAssembly().FullName).Name + ";component/Resources/"; var imageColumn = new DataGridImageColumn(e.Property); imageColumn.SortMemberPath = "ImageUrl"; imageColumn.Binding.Converter = new ImageSourceConverter(); imageColumn.Binding.ConverterParameter = imgPath; imageColumn.Width = new DataGridLength(85); imageColumn.GroupContentConverter = new ImageSourceConverter(); imageColumn.Format = imgPath; imageColumn.Header = "Image"; e.Column = imageColumn; } if (e.Property.Name == "ExpirationDate") { //(e.Column as DataGridDateColumn).SelectedDateFormat = C1DatePickerFormat.Custom; e.Column.GroupConverter = new OutlookDateGroupConverter(); e.Column.GroupContentConverter = new OutlookDateGroupNameConverter(); e.Column.Header = "Expiration Date"; } if (e.Property.Name == "Name") { IValueConverter converter = new AlphabeticTextGroupConverter(); e.Column.GroupConverter = converter; } if (e.Property.Name == "ProductNumber") { IValueConverter converter = new ProductGroupConverter(); e.Column.GroupConverter = converter; e.Column.GroupContentConverter = converter; e.Column.Header = "Product Number"; (e.Column as DataGridTextColumn).MaxLength = 10; } if (e.Property.Name == "StandardCost" && e.Column is C1.WPF.DataGrid.DataGridBoundColumn) { e.Column.GroupConverter = new NumberRangeGroupConverter(); e.Column.GroupContentConverter = new NumberRangeGroupNameConverter(); e.Column.Header = "Standard Cost"; ((C1.WPF.DataGrid.DataGridBoundColumn)e.Column).Format = "C"; } }
private void grid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { if (e.Property.Name == "Photo") { var imageCol = new DataGridImageColumn(e.Property); imageCol.CanUserMove = false; imageCol.Header = ""; imageCol.Binding.Converter = new ImageSourceConverter(); imageCol.Binding.ConverterParameter = "/" + new AssemblyName(Assembly.GetExecutingAssembly().FullName).Name + ";component/Resources/tennis/"; e.Column = imageCol; } if (e.Property.Name == "Birthday" && e.Column is DataGridBoundColumn) { ((DataGridBoundColumn)e.Column).Format = "d"; } if (e.Property.Name == "Website") { var hyperCol = new DataGridHyperlinkColumn(e.Property); //hyperCol.CellContentStyle = Resources["HyperlinkColumnStyle"] as Style; e.Column = hyperCol; } }
private void CustomGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { if (!string.IsNullOrEmpty(ColumnsToAdd) || !string.IsNullOrEmpty(ColumnsToRemove)) { string[] removeColumnsList = null; if (!string.IsNullOrEmpty(ColumnsToRemove)) { removeColumnsList = ColumnsToRemove.Split(','); if (removeColumnsList.Contains(e.Property.Name)) { e.Cancel = true; } } if (string.IsNullOrEmpty(ColumnsToRemove)) { string[] addColumnsList = null; if (!string.IsNullOrEmpty(ColumnsToAdd)) { addColumnsList = ColumnsToAdd.Split(','); if (!addColumnsList.Contains(e.Property.Name)) { e.Cancel = true; } } } } string dispalyName = GetDisplayName(e.Property.Name); if (e.Property.PropertyType == typeof(string) || e.Property.PropertyType == typeof(char)) { var customColumn = new CustomTextColumn(); if (e.Property.PropertyType == typeof(char)) { customColumn.MaxLength = 1; } if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); e.Column = customColumn; } if (e.Property.PropertyType.IsNumeric()) { var customColumn = new CustomNumericColumn(); if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); customColumn.Format = "0,0.##"; if (this.FlowDirection == FlowDirection.RightToLeft) { customColumn.HorizontalAlignment = HorizontalAlignment.Left; } e.Column = customColumn; } if (e.Property.PropertyType == typeof(bool) || e.Property.PropertyType == typeof(bool?)) { var customColumn = new CustomCheckBoxColumn(); if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); e.Column = customColumn; } if (e.Property.PropertyType == typeof(ImageSource)) { var customColumn = new DataGridImageColumn(); customColumn.IsReadOnly = true; if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.Binding = new Binding(e.Property.Name); e.Column = customColumn; } if (e.Property.PropertyType == typeof(DateTime) || e.Property.PropertyType == typeof(DateTime?)) { var customColumn = new CustomDateTimeColumn(); if (!string.IsNullOrEmpty(dispalyName)) { customColumn.Header = dispalyName; } else { customColumn.Header = e.Property.Name; } customColumn.IsReadOnly = true; customColumn.Binding = new Binding(e.Property.Name); customColumn.Format = "d"; if (this.FlowDirection == FlowDirection.RightToLeft) { customColumn.HorizontalAlignment = HorizontalAlignment.Left; } e.Column = customColumn; } }