简体   繁体   English

无法将类型'system.reflection.fieldinfo'隐式转换为'devexpress.dataaccess.excel.fieldinfo'

[英]cannot implicitly convert type 'system.reflection.fieldinfo' to 'devexpress.dataaccess.excel.fieldinfo'

Error Image 错误图片

thanks in advance to everyone.... i'm using devexpress xtragridcontrol to display data according to the rows hight. 在此先感谢大家。...我正在使用devexpress xtragridcontrol根据高行显示数据。 but got problem that, cannot implicitly convert type system.reflection.fieldinfo to devexpress.dataaccess.excel.fieldinfo, any suggestion... 但是有一个问题,无法将类型system.reflection.fieldinfo隐式转换为devexpress.dataaccess.excel.fieldinfo,任何建议...

here is my code 这是我的代码

private void UpdateGridSize()
{
    GridViewInfo viewInfo = (GridViewInfo)gridView2.GetViewInfo();
    DevExpress.DataAccess.Excel.FieldInfo fi = typeof(GridView).GetField("scrollInfo", BindingFlags.Instance | BindingFlags.NonPublic);
    ScrollInfo scrollInfo = (ScrollInfo)fi.GetValue(gridView2);
    int width = viewInfo.ViewRects.IndicatorWidth;
    foreach (GridColumn column in gridView1.VisibleColumns)
    {
        if (viewInfo.GetColumnLeftCoord(column) < viewInfo.ViewRects.ColumnPanelWidth)
            gridView1.LeftCoord = width;
        width += viewInfo.ColumnsInfo[column].Bounds.Width;
    }
    if (scrollInfo.VScrollVisible) width += scrollInfo.VScrollSize;
    int height = viewInfo.CalcRealViewHeight(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height), true);
    if (scrollInfo.HScrollVisible) height += scrollInfo.HScrollSize;
    width = Math.Max(GridMinWidth, width);
    width = Math.Min(ClientSize.Width - gridControl1.Location.X, width);
    height = Math.Max(GridMinHeight, height);
    height = Math.Min(ClientSize.Height - gridControl1.Location.Y, height);
    gridControl1.Size = new Size(width, height);
    gridView1.LayoutChanged();
}

The reflection and DevExpress FieldInfo types are not related and therefore not assignment compatible. 反射类型和DevExpress FieldInfo类型无关,因此不兼容分配。 Create a new object and assign the values 创建一个新对象并分配值

var fieldInfo = typeof(GridView).GetField("scrollInfo",
    BindingFlags.Instance | BindingFlags.NonPublic); // Reflection

var fi = new DevExpress.DataAccess.Excel.FieldInfo {
    Name = fieldInfo.Name, Type = fieldInfo.MemberType
};

Or did you mean to do something like this: 还是您要执行以下操作:

viewInfo.GetField(...)

instead of 代替

typeof(GridView).GetField(

According to DevExpress the class GridViewInfo is not documented and subject to changes 根据DevExpress 说法, GridViewInfo类未记录在案并可能会发生更改

This class is not documented, because it describes the internal visual grid presentation, which can be dynamically changed depending on development requirements. 该类未记录,因为它描述了内部可视化网格表示形式,可以根据开发要求对其进行动态更改。 We tend to prevent our customers from using this class. 我们倾向于防止客户使用此类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM