Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1960
Applying the same Appearance to all the grids on my application
posted

Hello,

I have created a set of Appearances to be set to the DisplayLayout.Override.RowAppearance, CellAppearance, etc.

I have a grid MyGrid that inherits from the UltraGrid, and I want all instances of MyGrid to display those Appearances by default. What's the most appropriate way of doing it?

Under my ideal scenario when the developer drags a MyGrid from the toolbox and drops it into the form, the appearances displayed by default are the ones I defined. Then the developer is free to make any changes he sees fit.

The closest I got was overriding the OnInitializeLayout method and set the Appearances of the DisplayLayout.Override. The problem is that any change the developer makes at design time will be lost at run time.

  • 37774
    Suggested Answer
    posted

    One approach might be to check the IsDesignMode property of the form that the grid is contained on when you override OnInitializeLayout and only apply your settings there (i.e. do "this.FindForm().IsDesignMode).  The downside to this is that sometimes this doesn't work if you're on, say, a user control, and you bind the grid through a host form; I can't remember the exact issues I've had in the past, but this isn't the cleanest approach.

    A better approach might be that since you're deriving your own grid, you could probably create your own designer too and apply it to your new grid.  This way, you are notified when the developer drops a new instance of your grid onto the form, instead of having to deal with the grid's events and losing settings at run-time.  The following snippet assumes that your assembly has a reference to System.Design and Infragistics2.Win.(version).Design:

    public class MyGridDesigner : UltraGridDesigner
    {
        public override void InitializeNewComponent(System.Collections.IDictionary defaultValues)
        {
            // Call the base first because I believe this is where the other presets are applied
            // from the registry to apply the standard defaults
            base.InitializeNewComponent(defaultValues);

            // Apply any logic necessary here
            UltraGrid grid = this.Control as UltraGrid;
        }
    }

    [Designer(typeof(MyGridDesigner))]
    public class MyGrid : UltraGrid
    {

    }

    -Matt