Hi all. I'm curious, being new o this type of development, on how to have changes post back to a Form/Control designer. I have read many articles on the subject but they seem to be tailored to what they are accomplishing but not generic enough to apply to other things. So I have created a custom control, added a toolBarsManager, added a PopupMenuTool.
I have a property on the custom control that accepts an UltraGrid.
[System.ComponentModel.Editor(typeof(CustomControls.UIDesigners.GridNavigatorGridEditor), typeof(System.Drawing.Design.UITypeEditor))]
public UltraGrid UltraGrid { get { return _ultraGrid; } set { _ultraGrid = value; if (_ultraGrid != null) { if (Presenter == null) Presenter = new GridNavigatorPresenter(this as GridNavigator); Presenter.FindFirstKeys = new List<string>(); GridNavigatorFilterSelection filterCreation = new GridNavigatorFilterSelection(); foreach (var col in _ultraGrid.DisplayLayout.Bands[0].Columns) { Presenter.FindFirstKeys.Add(col.Key); //List<string> } ToolBase[] toolBase = new ToolBase[Presenter.FindFirstKeys.Count]; int index = 0; foreach (string key in Presenter.FindFirstKeys) { //this section uses the designer's method CreateTool that builds the PopupToolMenu item with default set of StateButtonTools toolBase[index] = filterCreation.CreateTool(key, "String"); //by default, set all as strings index++; } this.ToolBarManager.Tools.AddRange(toolBase); //have to add the tools to the ToolbarManager before adding them to the actual Tool PopupMenuTool filterMenuTool = tbmNavigator.Tools["FilterPopupMenu"] as PopupMenuTool; filterMenuTool.Tools.AddRange(toolBase); //update the ui PropertyDescriptorCollection properties; properties = TypeDescriptor.GetProperties(typeof(M3InfragisticsGridNavigator));
//doesn’t update the ToolBarsManager PropertyDescriptor changedTS = properties.Find("ToolBar", false); changedTS.SetValue(navigator, navigator.ToolBarManager);
//Does add the PopupMenuTools, but doesn't add them to the ToolbarsManager PropertyDescriptor changedPopup = properties.Find("FilterMenuTool", false); changedPopup.SetValue(navigator, filterMenuTool);
//doesn’t add these (here is the StateButtonTools) PropertyDescriptor changedTools = properties.Find("FilterMenuTool.Tools", false); changedTools.SetValue(navigator, filterMenuTool.Tools); } OnPropertyChanged(nameof(UltraGrid)); }
My end goal is to be able to edit the existing PopupMenuTool (FilterMenuTool), add some child PopupToolMenu(s) that have StateButtonTools.
So, if anyone has done something like this where you created a CustomControl based on a 3rd party control and was able to access a collection that contains another collection and store that on the designer pls pls pls tell me (step by step would be nice).
Hi Glen,
As far as I can tell from the code provided, there's no reason why a toolbar or tool with the same key as the one you're trying to add should already exist. One method you might try in order to debug this to put a break point on the line that will throw the error and examine which tools/toolbars already exist.
Since you are building a designer, you will need to use a second instance of Visual Studio to debug. Take the following steps:
Please try this out and let me know what you find.
Hi Mike and thanks for replying.
"How are you trying to edit an existing tool? Do you need to do this at design time or at run time?" I wrote a ControlDesigner that displays the PopupMenuTools that are generated based on the columns in the grid. But for now, I'm skipping that since I still need to create the PopupMenuTools when an UltraGrid is assigned.
"I'm not sure what you mean when you say that you want to "store" a collection on the designer. Are you able to clarify this requirement?" I orignally wanted to create a collection of PopupMenuTools with State buttons that was to be edited with a ControlDesigner. Right now, I'm rethinking that approach since I have to figure out how to Add the StateButtons.
When a developer drags the custom usercontrol onto the design surface (another control or form) I want them to be able to assign an existing ultragrid and based on the columns, add a set of popupmenus with statebuttons in designmode (not runtime). I tried adding the StateButtonTools on the ToolBarsManager on the usercontrol 1st, but after adding them to the PopupMenuTools I get a duplicate key error at runtime. So I removed all the StateButtonTools and created them in the property below. Sadly I still get the same message on "pmt.Tools.AddTool(sbtBetween.Key);" that the Key already exist. So I'm confused as to what to do or how to get around this.
My understanding is that before I can add a StateButtonTool to a PopMenuTool, the StateButtonTool has to exist on the ToolBarsManager. Now I went as far as designing the UserControl with the UltraToolBarsManager, adding some default buttons for navigation, added a textbox for searching, a PopupMenuTool (this is where I want to add more PopupMenuTools with StateButtonTools) and a tetbox for what to filter on.
So my problem is when the UserControl is dragged onto a form it creates the code in the designer as expected. Howevr, when you try to launch the form it gives the "Key already in use" message. I haven't gotten to the adding the PopupMenuTools / StateButtonTools yet. Here is the designer code generated:
partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Windows Form Designer generated code
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); Infragistics.Win.UltraWinGrid.UltraGridBand ultraGridBand1 = new Infragistics.Win.UltraWinGrid.UltraGridBand("Band 0", -1); Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn1 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("ID"); Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn2 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("FirstName"); Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn3 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("LastName"); Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn4 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("Email"); Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn5 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("Country"); Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn1 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("ID"); Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn2 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("FirstName"); Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn3 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("LastName"); Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn4 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("Email"); Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn5 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("Country"); Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance(); Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("tbNavigator"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MoveFirst"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MovePrevious"); Infragistics.Win.UltraWinToolbars.TextBoxTool textBoxTool1 = new Infragistics.Win.UltraWinToolbars.TextBoxTool("CurrentRow"); Infragistics.Win.UltraWinToolbars.LabelTool labelTool1 = new Infragistics.Win.UltraWinToolbars.LabelTool("TotalRows"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MoveNext"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool4 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MoveLast"); Infragistics.Win.UltraWinToolbars.LabelTool labelTool2 = new Infragistics.Win.UltraWinToolbars.LabelTool("Search"); Infragistics.Win.UltraWinToolbars.TextBoxTool textBoxTool2 = new Infragistics.Win.UltraWinToolbars.TextBoxTool("SearchValue"); Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool1 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("FilterPopupMenu"); Infragistics.Win.UltraWinToolbars.TextBoxTool textBoxTool3 = new Infragistics.Win.UltraWinToolbars.TextBoxTool("FilterValue"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool5 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MoveFirst"); Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool6 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MovePrevious"); Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance(); Infragistics.Win.UltraWinToolbars.TextBoxTool textBoxTool4 = new Infragistics.Win.UltraWinToolbars.TextBoxTool("CurrentRow"); Infragistics.Win.UltraWinToolbars.LabelTool labelTool3 = new Infragistics.Win.UltraWinToolbars.LabelTool("TotalRows"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool7 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MoveNext"); Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance(); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool8 = new Infragistics.Win.UltraWinToolbars.ButtonTool("MoveLast"); Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance(); Infragistics.Win.UltraWinToolbars.LabelTool labelTool4 = new Infragistics.Win.UltraWinToolbars.LabelTool("Search"); Infragistics.Win.UltraWinToolbars.TextBoxTool textBoxTool5 = new Infragistics.Win.UltraWinToolbars.TextBoxTool("SearchValue"); Infragistics.Win.UltraWinToolbars.TextBoxTool textBoxTool6 = new Infragistics.Win.UltraWinToolbars.TextBoxTool("FilterValue"); Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool2 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("FilterPopupMenu"); Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance(); this.ultraGrid1 = new Infragistics.Win.UltraWinGrid.UltraGrid(); this.ultraDataSource1 = new Infragistics.Win.UltraWinDataSource.UltraDataSource(this.components); this.gridNavigator1 = new M3.InfragisticsCustomControls.gridNavigator(); ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ultraDataSource1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.gridNavigator1.ToolBarManager)).BeginInit(); this.SuspendLayout(); // // ultraGrid1 // this.ultraGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.ultraGrid1.DataSource = this.ultraDataSource1; ultraGridColumn1.Header.VisiblePosition = 0; ultraGridColumn1.Width = 261; ultraGridColumn2.Header.VisiblePosition = 1; ultraGridColumn2.Width = 187; ultraGridColumn3.Header.VisiblePosition = 2; ultraGridColumn3.Width = 169; ultraGridColumn4.Header.VisiblePosition = 3; ultraGridColumn4.Width = 210; ultraGridColumn5.Header.VisiblePosition = 4; ultraGridColumn5.Width = 189; ultraGridBand1.Columns.AddRange(new object[] { ultraGridColumn1, ultraGridColumn2, ultraGridColumn3, ultraGridColumn4, ultraGridColumn5}); this.ultraGrid1.DisplayLayout.BandsSerializer.Add(ultraGridBand1); this.ultraGrid1.Location = new System.Drawing.Point(0, 1); this.ultraGrid1.Name = "ultraGrid1"; this.ultraGrid1.Size = new System.Drawing.Size(1059, 423); this.ultraGrid1.TabIndex = 1; this.ultraGrid1.AfterCellActivate += new System.EventHandler(this.ultraGrid1_AfterCellActivate); this.ultraGrid1.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.ultraGrid1_InitializeLayout); this.ultraGrid1.BindingContextChanged += new System.EventHandler(this.ultraGrid1_BindingContextChanged); this.ultraGrid1.Resize += new System.EventHandler(this.ultraGrid1_Resize); // // ultraDataSource1 // ultraDataColumn1.DataType = typeof(System.Guid); ultraDataColumn2.DefaultValue = ""; ultraDataColumn3.DefaultValue = ""; ultraDataColumn4.DefaultValue = ""; ultraDataColumn5.DefaultValue = ""; this.ultraDataSource1.Band.Columns.AddRange(new object[] { ultraDataColumn1, ultraDataColumn2, ultraDataColumn3, ultraDataColumn4, ultraDataColumn5}); this.ultraDataSource1.CellDataRequested += new Infragistics.Win.UltraWinDataSource.CellDataRequestedEventHandler(this.ultraDataSource1_CellDataRequested); this.ultraDataSource1.RowAdded += new Infragistics.Win.UltraWinDataSource.RowAddedEventHandler(this.ultraDataSource1_RowAdded); // // gridNavigator1 // this.gridNavigator1.Dock = System.Windows.Forms.DockStyle.Bottom; this.gridNavigator1.Location = new System.Drawing.Point(0, 464); this.gridNavigator1.Name = "gridNavigator1"; this.gridNavigator1.Size = new System.Drawing.Size(1059, 26); this.gridNavigator1.TabIndex = 2; // // // appearance1.FontData.Name = "Verdana"; this.gridNavigator1.ToolBarManager.Appearance = appearance1; this.gridNavigator1.ToolBarManager.DesignerFlags = 0; this.gridNavigator1.ToolBarManager.DockWithinContainer = this.gridNavigator1; this.gridNavigator1.ToolBarManager.LockToolbars = true; this.gridNavigator1.ToolBarManager.SettingsKey = ""; this.gridNavigator1.ToolBarManager.ShowFullMenusDelay = 500; this.gridNavigator1.ToolBarManager.Style = Infragistics.Win.UltraWinToolbars.ToolbarStyle.ScenicRibbon; ultraToolbar1.DockedColumn = 0; ultraToolbar1.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom; ultraToolbar1.DockedRow = 0; buttonTool3.InstanceProps.IsFirstInGroup = true; buttonTool4.InstanceProps.IsFirstInGroup = true; textBoxTool3.InstanceProps.IsFirstInGroup = true; ultraToolbar1.NonInheritedTools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { buttonTool1, buttonTool2, textBoxTool1, labelTool1, buttonTool3, buttonTool4, labelTool2, textBoxTool2, popupMenuTool1, textBoxTool3}); ultraToolbar1.Text = "tbNavigator"; this.gridNavigator1.ToolBarManager.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] { ultraToolbar1}); this.gridNavigator1.ToolBarManager.ToolbarSettings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False; appearance2.Image = ((object)(resources.GetObject("appearance2.Image"))); buttonTool5.SharedPropsInternal.AppearancesSmall.Appearance = appearance2; buttonTool5.SharedPropsInternal.Caption = "Move First"; buttonTool5.SharedPropsInternal.Category = "Navigation"; appearance3.Image = ((object)(resources.GetObject("appearance3.Image"))); buttonTool6.SharedPropsInternal.AppearancesSmall.Appearance = appearance3; buttonTool6.SharedPropsInternal.Caption = "Move Previous"; buttonTool6.SharedPropsInternal.Category = "Navigation"; textBoxTool4.SharedPropsInternal.Caption = "CurrentRow"; textBoxTool4.SharedPropsInternal.Category = "Navigation"; textBoxTool4.SharedPropsInternal.Width = 50; labelTool3.SharedPropsInternal.Caption = "Total Rows"; labelTool3.SharedPropsInternal.Category = "Navigation"; labelTool3.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.TextOnlyAlways; appearance4.Image = ((object)(resources.GetObject("appearance4.Image"))); buttonTool7.SharedPropsInternal.AppearancesSmall.Appearance = appearance4; buttonTool7.SharedPropsInternal.Caption = "Move Next"; buttonTool7.SharedPropsInternal.Category = "Navigation"; appearance5.Image = ((object)(resources.GetObject("appearance5.Image"))); buttonTool8.SharedPropsInternal.AppearancesSmall.Appearance = appearance5; buttonTool8.SharedPropsInternal.Caption = "Move Last"; buttonTool8.SharedPropsInternal.Category = "Navigation"; labelTool4.SharedPropsInternal.Caption = "First:"; labelTool4.SharedPropsInternal.Category = "Navigation"; textBoxTool5.SharedPropsInternal.Caption = "Search Value"; textBoxTool5.SharedPropsInternal.Category = "Search"; textBoxTool6.SharedPropsInternal.Caption = "Filter Value"; textBoxTool6.SharedPropsInternal.Category = "Filter"; popupMenuTool2.DropDownArrowStyle = Infragistics.Win.UltraWinToolbars.DropDownArrowStyle.None; popupMenuTool2.InstanceProps.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageOnlyOnToolbars; popupMenuTool2.Settings.ToolDisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageOnlyOnToolbars; popupMenuTool2.Settings.UseLargeImages = Infragistics.Win.DefaultableBoolean.False; appearance6.Image = ((object)(resources.GetObject("appearance6.Image"))); popupMenuTool2.SharedPropsInternal.AppearancesSmall.Appearance = appearance6; popupMenuTool2.SharedPropsInternal.Category = "Filter"; popupMenuTool2.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText; this.gridNavigator1.ToolBarManager.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { buttonTool5, buttonTool6, textBoxTool4, labelTool3, buttonTool7, buttonTool8, labelTool4, textBoxTool5, textBoxTool6, popupMenuTool2}); this.gridNavigator1.UltraGrid = null; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1059, 490); this.Controls.Add(this.gridNavigator1); this.Controls.Add(this.ultraGrid1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.Resize += new System.EventHandler(this.Form1_Resize); ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.ultraDataSource1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.gridNavigator1.ToolBarManager)).EndInit(); this.ResumeLayout(false);
}
#endregion private Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid1; private Infragistics.Win.UltraWinDataSource.UltraDataSource ultraDataSource1; private CustomControls.GridNavigator gridNavigator1; }
So when it gets to this line of code (in the designer) I get the following error message: Key already existsParameter name: Key
this.gridNavigator1.ToolBarManager.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] { ultraToolbar1}); So to recap, all I've done is create a ToolBarsManager on a UserControl, added some default items.
the UserControls constructor: public GridNavigator() { InitializeComponent();
this.GetType().GetProperty("Dock").SetValue(this, DockStyle.Bottom);
Infragistics.Win.Appearance filterImage = new Infragistics.Win.Appearance(); filterImage.Image = global::M3.InfragisticsCustomControls.Properties.Resources.filter;
//Infragistics.Win.UltraWinToolbars.PopupMenuTool FilterMenuTool = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("FilterPopupMenu");
PopupMenuTool filterMenuTool = tbmNavigator.Tools["FilterPopupMenu"] as PopupMenuTool;
filterMenuTool.DropDownArrowStyle = Infragistics.Win.UltraWinToolbars.DropDownArrowStyle.None; filterMenuTool.InstanceProps.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageOnlyOnToolbars; filterMenuTool.Settings.ToolDisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageOnlyOnToolbars; filterMenuTool.Settings.UseLargeImages = Infragistics.Win.DefaultableBoolean.False;
filterMenuTool.SharedPropsInternal.AppearancesSmall.Appearance = filterImage; filterMenuTool.SharedPropsInternal.Category = "Filter"; filterMenuTool.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;
For giggles, I tried editing the form designer and removing all the controls except for the ultraToolbar1 and it still says the Key error message. At this point I'm not sure what to do.
Hi Glenn,
I am not certain that I fully understand your requirement, but I will provide whatever information I can.
The Designer Surface reflects any changes made to the control in the designer.cs file. This file is generated automatically by Visual Studio and should normally not be edited manually. It is preferred to make changes through the designer itself, and VS will update the designer.cs to reflect these changes.
How are you trying to edit an existing tool? Do you need to do this at design time or at run time?
I'm not sure what you mean when you say that you want to "store" a collection on the designer. Are you able to clarify this requirement?