private static void AddBoundColumn(DataGridColumnCollection columns, string name) { BoundColumn column = new BoundColumn(); column.DataField = name; column.HeaderText = name; column.SortExpression = name; columns.Add(column); }
/// <summary>Initializes a new instance of the <see cref="DataGrid"/> class. </summary> public DataGrid() { DefaultStyleKey = typeof(DataGrid); Columns = new DataGridColumnCollection(); // Initialize collection so that columns can be defined in XAML if (!Designer.IsInDesignMode) { Loaded += OnLoaded; } }
private static DataGridColumnCollectionBehaviour GetOrCreateBehaviour(DependencyObject source) { DataGridColumnCollectionBehaviour behaviour = DataGridColumnCollection.GetColumnCollectionBehaviour(source); if (behaviour == null) { behaviour = new DataGridColumnCollectionBehaviour(source as DataGrid); DataGridColumnCollection.SetColumnCollectionBehaviour(source, behaviour); } return(behaviour); }
/// <include file='doc\DataGridDesigner.uex' path='docs/doc[@for="DataGridDesigner.GetCachedTemplateEditingVerbs"]/*' /> protected override TemplateEditingVerb[] GetCachedTemplateEditingVerbs() { if (templateVerbsDirty == true) { DisposeTemplateVerbs(); DataGridColumnCollection columns = dataGrid.Columns; int columnCount = columns.Count; if (columnCount > 0) { int templateColumns = 0; int i, t; for (i = 0; i < columnCount; i++) { if (columns[i] is TemplateColumn) { templateColumns++; } } if (templateColumns > 0) { templateVerbs = new TemplateEditingVerb[templateColumns]; for (i = 0, t = 0; i < columnCount; i++) { if (columns[i] is TemplateColumn) { string headerText = columns[i].HeaderText; string caption = "Columns[" + (i).ToString() + "]"; if ((headerText != null) && (headerText.Length != 0)) { caption = caption + " - " + headerText; } templateVerbs[t] = new TemplateEditingVerb(caption, i, this); t++; } } } } templateVerbsDirty = false; } return(templateVerbs); }
protected override TemplateEditingVerb[] GetCachedTemplateEditingVerbs() { if (this.templateVerbsDirty) { this.DisposeTemplateVerbs(); DataGridColumnCollection columns = ((DataGrid)base.Component).Columns; int count = columns.Count; if (count > 0) { int num3; int num2 = 0; for (num3 = 0; num3 < count; num3++) { if (columns[num3] is TemplateColumn) { num2++; } } if (num2 > 0) { this.templateVerbs = new TemplateEditingVerb[num2]; num3 = 0; int index = 0; while (num3 < count) { if (columns[num3] is TemplateColumn) { string headerText = columns[num3].HeaderText; string text = "Columns[" + num3.ToString(NumberFormatInfo.CurrentInfo) + "]"; if ((headerText != null) && (headerText.Length != 0)) { text = text + " - " + headerText; } this.templateVerbs[index] = new TemplateEditingVerb(text, num3, this); index++; } num3++; } } } this.templateVerbsDirty = false; } return(this.templateVerbs); }
/// <summary> /// Instantiates a new instance of this class. /// </summary> public DataGrid() { _columns = new DataGridColumnCollection(this); _columns.CollectionChanged += new NotifyCollectionChangedEventHandler(OnColumnsChanged); _rowValidationRules = new ObservableCollection<ValidationRule>(); _rowValidationRules.CollectionChanged += new NotifyCollectionChangedEventHandler(OnRowValidationRulesChanged); _selectedCells = new SelectedCellsCollection(this); ((INotifyCollectionChanged)Items).CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemsCollectionChanged); ((INotifyCollectionChanged)Items.SortDescriptions).CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemsSortDescriptionsChanged); Items.GroupDescriptions.CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemsGroupDescriptionsChanged); // Compute column widths but wait until first load InternalColumns.InvalidateColumnWidthsComputation(); CellsPanelHorizontalOffsetComputationPending = false; }
private void InitFormatTree() { FormatTreeNode node; FormatObject obj2; if (base.IsDataGridMode) { System.Web.UI.WebControls.DataGrid baseControl = (System.Web.UI.WebControls.DataGrid)base.GetBaseControl(); obj2 = new FormatStyle(baseControl.ControlStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_EntireDG"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(baseControl.HeaderStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Header"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(baseControl.FooterStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Footer"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(baseControl.PagerStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Pager"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); FormatTreeNode node2 = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Items"), null); this.formatTree.Nodes.Add(node2); obj2 = new FormatStyle(baseControl.ItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_NormalItems"), obj2); node2.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(baseControl.AlternatingItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_AltItems"), obj2); node2.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(baseControl.SelectedItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_SelItems"), obj2); node2.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(baseControl.EditItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_EditItems"), obj2); node2.Nodes.Add(node); this.formatNodes.Add(node); DataGridColumnCollection columns = baseControl.Columns; int count = columns.Count; if (count != 0) { FormatTreeNode node3 = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Columns"), null); this.formatTree.Nodes.Add(node3); for (int i = 0; i < count; i++) { DataGridColumn runtimeColumn = columns[i]; string text = "Columns[" + i.ToString(NumberFormatInfo.CurrentInfo) + "]"; string headerText = runtimeColumn.HeaderText; if (headerText.Length != 0) { text = text + " - " + headerText; } obj2 = new FormatColumn(runtimeColumn); obj2.LoadFormatInfo(); FormatTreeNode node4 = new FormatTreeNode(text, obj2); node3.Nodes.Add(node4); this.formatNodes.Add(node4); obj2 = new FormatStyle(runtimeColumn.HeaderStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Header"), obj2); node4.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(runtimeColumn.FooterStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Footer"), obj2); node4.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(runtimeColumn.ItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Items"), obj2); node4.Nodes.Add(node); this.formatNodes.Add(node); } } } else { DataList list = (DataList)base.GetBaseControl(); obj2 = new FormatStyle(list.ControlStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_EntireDL"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(list.HeaderStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Header"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(list.FooterStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Footer"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); FormatTreeNode node5 = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Items"), null); this.formatTree.Nodes.Add(node5); obj2 = new FormatStyle(list.ItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_NormalItems"), obj2); node5.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(list.AlternatingItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_AltItems"), obj2); node5.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(list.SelectedItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_SelItems"), obj2); node5.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(list.EditItemStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_EditItems"), obj2); node5.Nodes.Add(node); this.formatNodes.Add(node); obj2 = new FormatStyle(list.SeparatorStyle); obj2.LoadFormatInfo(); node = new FormatTreeNode(System.Design.SR.GetString("BDLFmt_Node_Separators"), obj2); this.formatTree.Nodes.Add(node); this.formatNodes.Add(node); } }
// <Snippet1> void Page_Init(Object sender, EventArgs e) { ArrayList myList = new ArrayList(); DataGridColumnCollection myColumnCollection = new DataGridColumnCollection(ItemsGrid, myList); }
private static void WidthMemberChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DataGridColumnCollection.GetOrCreateBehaviour(sender).WidthMember = e.NewValue as string; }
private static void ColumnsSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DataGridColumnCollection.GetOrCreateBehaviour(sender).ColumnsSource = e.NewValue; }