devexpress GridControl中没有调用方法CreateDefaultView()
The method CreateDefaultView () is not called in devexpress GridControl
我继承了一个 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 的属性,但从未调用过。
这可能是什么原因?
当 MainView
属性 为 null
时调用此事件。这意味着当您在设计时或运行时向窗体添加新 gttGridControl
时将调用此事件。
这是运行时的示例:
var gridControl = new gttDXGridControl();
gridControl.Width = 100;
gridControl.Height = 100;
Controls.Add(gridControl); // => Here this event will be invoked.
我继承了一个 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 的属性,但从未调用过。 这可能是什么原因?
当 MainView
属性 为 null
时调用此事件。这意味着当您在设计时或运行时向窗体添加新 gttGridControl
时将调用此事件。
这是运行时的示例:
var gridControl = new gttDXGridControl();
gridControl.Width = 100;
gridControl.Height = 100;
Controls.Add(gridControl); // => Here this event will be invoked.