protected void OnGridViewInit(object sender, EventArgs e) { CustomColumn column = new CustomColumn(); column.DataField = BoundField.ThisExpression; gridView.Columns.Add(column); }
public override object Clone() { CustomColumn copy = base.Clone() as CustomColumn; copy.type = type; return(copy); }
public CustomColumn[] CustomizeListView(ListView L) { CustomColumn[] cColArray = new CustomColumn[L.Columns.Count]; for (int i = 0; i < L.Columns.Count; i++) { ColumnHeader col = L.Columns[i]; CustomColumn cc = new CustomColumn(); cc.ImageFile = String.Empty; if (col.Image != null) { cc.ImageFile = col.Image.File; } cc.Index = col.Index; cc.Name = col.Name; //cc.Position = col.Position; cc.Text = col.Text; cc.Visible = col.Visible; cc.Width = col.Width; cColArray[i] = cc; } return(cColArray); }
protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem) { TextBlock block = new TextBlock(); CustomColumn column = (CustomColumn)cell.Column; Binding binding = (Binding)column.Binding; if (binding != null) { // Binde den ausgewählten Wert Binding cellBinding = new Binding(binding.Path.Path); cellBinding.Source = dataItem; cellBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; cellBinding.ValidatesOnDataErrors = true; cellBinding.ValidatesOnExceptions = true; cellBinding.NotifyOnValidationError = true; cellBinding.ValidatesOnNotifyDataErrors = true; cellBinding.Mode = BindingMode.OneWay; block.SetBinding(TextBlock.TextProperty, cellBinding); } return(block); }
private static IEnumerable <Column> GenerateColumns <T>() { var list = new List <Column>(); var type = typeof(T); var members = type.GetProperties(); foreach (var propertyInfo in members) { var attr = Attribute.GetCustomAttribute(propertyInfo, typeof(ShowInUiAttribute)); if (attr != null) { var c = new CustomColumn(); c.FieldName = propertyInfo.Name; c.AllowGroup = false; c.Title = propertyInfo.Name; if ((propertyInfo.PropertyType == typeof(DateTime)) || (propertyInfo.PropertyType == typeof(DateTime?))) { var newTextBlock = new FrameworkElementFactory(typeof(TextBlock)); newTextBlock.SetBinding(TextBlock.TextProperty, new Binding(".") { StringFormat = @"{0:dd.MM.yy HH:mm:ss}" }); var newDataTemplate = new DataTemplate { VisualTree = newTextBlock }; c.CellContentTemplate = newDataTemplate; } list.Add(c); } } return(list); }
protected void OnGridViewInit (object sender, EventArgs e) { CustomColumn column = new CustomColumn (); column.DataField = BoundField.ThisExpression; gridView.Columns.Add (column); }
/// <summary> /// Metodo che inizializza lo UserControl con gli elementi base della SmartGrid e salva in sessione i dati necessari alla renderizzazione della SmartGrid /// </summary> /// <param name="objects">DataSource della SmartGrid</param> /// <param name="lengthMenu">Permette la selezione del numero di righe della SmartGrid</param> /// <param name="horizontalSearch">Abilita la ricerca orizzontale</param> private void SetDataSource<T>(List<T> objects, bool lengthMenu, bool horizontalSearch, List<ButtonTypeEnum> btns) { try { List<object> Objects = objects.Cast<object>().ToList(); GetProperyInfo<T>(objects); if (ListSmartGridColumnInfo == null || ListSmartGridColumnInfo.Count == 0) return; CreateTable(); int width = 100 / ListSmartGridColumnInfo .Count(x => x.Attribute.Visible); List<object> Columns = new List<object>(), ColumnsDefs = new List<object>(); int index = 0; ListSmartGridColumnInfo .ToList() .ForEach(x => { if (x.Attribute.isDataRowKey) { DataRowKey = x.PropertyName; MultipleActionDataValue = !x.Attribute.MultipleActionDataField.StartsWith("!"); MultipleActionDataField = x.Attribute.MultipleActionDataField.Substring(MultipleActionDataValue ? 0 : 1); } x.Attribute.ColumnTypes.ForEach( y => { object col, colDef; switch (y) { case SmartGridAttribute.ColumnTypeEnum.DetailColumn: case SmartGridAttribute.ColumnTypeEnum.EditColumn: case SmartGridAttribute.ColumnTypeEnum.DeleteColumn: col = new CustomColumn(x, y); colDef = new StringColumnDef(); break; case SmartGridAttribute.ColumnTypeEnum.CheckBox: case SmartGridAttribute.ColumnTypeEnum.Date: col = new StringColumn(x, width, y, false); colDef = new CostumColumnDef(x, index, y); break; case SmartGridAttribute.ColumnTypeEnum.Currency: case SmartGridAttribute.ColumnTypeEnum.Decimal2Places: case SmartGridAttribute.ColumnTypeEnum.Decimal4Places: col = new StringColumn(x, width, y, true); colDef = new CostumColumnDef(x, index, y); break; default: col = new StringColumn(x, width, y); colDef = new StringColumnDef(); break; } Columns.Add(col); ColumnsDefs.Add(colDef); index++; }); }); SmartGridData smartGridData = new SmartGridData(); var jsonSerialiser = new JavaScriptSerializer(); bool btnFeatures = false; if (btns != null && btns.Count > 0) { List<string> renderedButtons = new List<string>(); btns.ForEach(x => { renderedButtons.Add(x.ToString()); }); btnFeatures = true; smartGridData.Buttons = jsonSerialiser.Serialize(renderedButtons); } smartGridData.sDom = string.Format(sDom, lengthMenu ? "l" : "", btnFeatures ? "B" : "", horizontalSearch ? "f" : ""); smartGridData.Objects = jsonSerialiser.Serialize(Objects); smartGridData.Columns = jsonSerialiser.Serialize(Columns); smartGridData.ColumnsDefs = jsonSerialiser.Serialize(ColumnsDefs); System.Web.HttpContext.Current.Session.Add("SmartGridData", smartGridData); } catch (Exception /*ex*/) { //Logger.LogException(ex); //(Page as Default).errors.Add("Errore in fase di caricamento della SmartGrid"); } }