Hi All,
I created a user control incorporating an ultragrid besides some other controls that I want to use to display additional information about and interact with the grid in a certain way. This control I am going to be using everywhere the grid would go. Unfortunately it seems that in spite all my efforts I am not able to make this control to reveal the grid designer at design time. The control has a public property called say, TheGrid returning the UltraGrid in my UserControl but I don't know how I am supposed to let the designer know how to edit this property with the designer.
What I tried was to decorate my usercontrol with the DesignerAttribute
[Designer("Infragistics.Win.UltraWinGrid.Design.UltraGridDesigner, Infragistics2.Win.v10.3.Design, Version=10.3.20103.2145, Culture=neutral")]
as well as using all the other forms of this constructor. This will crash the designer complaining about a null pointer to the grid which I can see why it's happening since my UserControl is not a grid.
Also, I tried using an Editor attribute on the TheGrid property but I didn't get very far either. The code is below:
//[Designer("Infragistics.Win.UltraWinGrid.Design.UltraGridDesigner, Infragistics2.Win.v10.3.Design, Version=10.3.20103.2145, Culture=neutral")] public partial class StableGridX : UserControl { public StableGridX() { InitializeComponent(); _saveFilterBtn.Click += (sender, e) => _theGrid.SaveCurrentFilter(); _resetFilterBtn.Click += (sender, e) => _theGrid.Rows.ColumnFilters.ClearAllFilters(); _namedFiltersCtl.DataSource = _theGrid.NamedFilters; _namedFiltersCtl.DisplayMember = "Name"; _namedFiltersCtl.SelectionChangeCommitted += (sender, e) => _theGrid.ApplyFilter((NamedFiltersEntry)_namedFiltersCtl.SelectedItem); } [Browsable(true)] [Editor(typeof(StableGrid), typeof(UltraGridDesigner))] public StableGrid TheGrid { get { return _theGrid; } } public static implicit operator StableGrid(StableGridX ctl) { return ctl._theGrid; } }
How can this be achieved? I want the grid designer to pop up when I want to edit TheGrid property?
Hi,
I'm not sure if this is possible. The reason the attribute doesn't work is that the designer is assuming that the control it's designing is an UltraGridBase and your control is not.
The designer class cannot be display via a property as a UITypeEditor, because it's not a UITypeEditor, it's a designer.
If the grid designer dialog class is public (it's in the Infragistics.Win.Design assembly) then it might be possible for you to create your own UITypeEditor that displays the designer dialog, but I suspect that the dialog is not public and even if it is, I haven't tried it, so I don't know if it will work.
Thank you Mike for the answer although it wasn't what I hoped for. I eventually figured out myself whay the posted code wouldn't work (my UserControl is not a Grid and hence it cannot be designed with the GridDesigner and as far as UITypeEditors go I wouldn't know how to display the editor since I cannot see any public method in it that will do that).
In any case I spent almost two days on this and I managed to scramble something that might pass as a solution:
using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using System.Windows.Forms.Design; namespace Jpmc.PB.Stable.ApplicationTechnicalServices.UIServices.ComponentsLib { [Designer("Jpmc.PB.Stable.ApplicationTechnicalServices.UIServices.ComponentsLib.MyControlDesigner, Jpmc.PB.Stable.ApplicationTechnicalServices.UIServices.ComponentsLib")] public partial class StableGridX : UserControl { public StableGridX() { InitializeComponent(); _saveFilterBtn.Click += (sender, e) => _theGrid.SaveCurrentFilter(); _resetFilterBtn.Click += (sender, e) => _theGrid.Rows.ColumnFilters.ClearAllFilters(); _namedFiltersCtl.DataSource = _theGrid.NamedFilters; _namedFiltersCtl.DisplayMember = "Name"; _namedFiltersCtl.SelectionChangeCommitted += (sender, e) => _theGrid.ApplyFilter((NamedFiltersEntry)_namedFiltersCtl.SelectedItem); } [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public StableGrid TheGrid { get { return _theGrid; } } public static implicit operator StableGrid(StableGridX ctl) { return ctl.TheGrid; } } public class MyControlDesigner : ParentControlDesigner { private StableGridX _stableGridX; private IDesignerHost _designerHost; private bool _disableDrawGrid; public override void Initialize(IComponent component) { base.Initialize(component); _stableGridX = component as StableGridX; if (_stableGridX != null) EnableDesignMode(_stableGridX.TheGrid, "TheGrid"); _designerHost = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost)); } public override int NumberOfInternalControlDesigners() { return 1; } public override ControlDesigner InternalControlDesigner(int internalControlIndex) { return _designerHost.GetDesigner(_stableGridX.TheGrid) as ControlDesigner; } protected override bool AllowControlLasso { get { return false; } } protected override void OnPaintAdornments(PaintEventArgs pe) { try { _disableDrawGrid = true; base.OnPaintAdornments(pe); } finally { _disableDrawGrid = false; } } public override bool CanParent(Control control) { return false; } protected override bool DrawGrid { get { if (_disableDrawGrid) return false; return base.DrawGrid; } } } }
Now this designer allows me to invoke the grid designer on the portion of the control that represents the grid and it correctly generates the code in the .designer.cs file.
Cheers, hope this helps others!