在devexpress GridControl中不调用CreateDefaultView()方法

时间:2016-02-04 09:57:54

标签: c# devexpress devexpress-windows-ui

我继承了一个devexpress GridControl,遵循here的所有步骤。

只有一个问题, 永远不会调用CreateDefaultView()方法。

这是代码:

public partial class gttDXGridControl : GridControl
{
    public gttDXGridControl() : base()
    { }

    protected override void RegisterAvailableViewsCore(InfoCollection collection)
    {
        base.RegisterAvailableViewsCore(collection);
        collection.Add(new gttDXGridViewInfoRegistrator());
    }

    //this event is not called for some reason...
    protected override BaseView CreateDefaultView()
    {
        gttDXGridView gridView = CreateView("gttGridView") as gttDXGridView;
        // would like to initialize stuff here...
        return gridView;
    }
}

public partial class gttDXGridViewInfoRegistrator : DevExpress.XtraGrid.Registrator.GridInfoRegistrator
{
    public override string ViewName { get { return "gttGridView"; } }
    public override BaseView CreateView(GridControl grid) { return new gttDXGridView(grid as GridControl); }
    public override BaseViewInfo CreateViewInfo(BaseView view) { return new gttDXGridViewInfo(view as gttDXGridView); }
    public override BaseViewHandler CreateHandler(BaseView view) { return new gttDXGridHandler(view as gttDXGridView); }

}

public partial class gttDXGridViewInfo : GridViewInfo
{
    public gttDXGridViewInfo(DevExpress.XtraGrid.Views.Grid.GridView gridView) : base(gridView)
    { }

    public override int CalcRowHeight(Graphics graphics, int rowHandle, int min, int level, bool useCache, GridColumnsInfo columns)
    {
        return base.CalcRowHeight(graphics, rowHandle, MinRowHeight, level, useCache, columns);
    }

    public override int MinRowHeight
    {
        get { return base.MinRowHeight - 2; }
    }
}

此事件是初始化GridView属性的地方,但它从未调用过。 可能是什么原因造成的?

1 个答案:

答案 0 :(得分:1)

null属性为gttGridControl时,将调用此事件。这意味着当您在设计时或运行时向表单添加新var gridControl = new gttDXGridControl(); gridControl.Width = 100; gridControl.Height = 100; Controls.Add(gridControl); // => Here this event will be invoked. 时,将调用此事件 以下是运行时的示例:

s