C# DevExpress.XtraGrid.gridControl异常
程序中使用DevExpress.XtraGrid.gridControl用绑定datatable的方式显示数据,但显示时出现了异常,gridControl控件部分画了个大...
程序中使用DevExpress.XtraGrid.gridControl用绑定datatable的方式显示数据,但显示时出现了异常,gridControl控件部分画了个大叉。提示异常错误如下:
************** Exception Text **************
System.NullReferenceException:
Object reference not set to an instance of an object.
at
DevExpress.Utils.AppearanceObject.CalcDefaultTextSize(Graphics g)
at
DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSizeCore(GraphicsCache
cache, String text, Int32 maxWidth)
at
DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSizeCore(Graphics g,
String text, Int32 maxWidth)
at
DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSize(Graphics g,
Boolean useDisplayText)
at
DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo.CalcTextSize(Graphics g,
Boolean useDisplayText)
at
DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo.CalcBestFitTextSize(Graphics
g)
at
DevExpress.XtraEditors.ViewInfo.BaseEditViewInfo.CalcBestFit(Graphics g)
at DevExpress.XtraEditors.ViewInfo.TextEditViewInfo.CalcMinHeightCore(Graphics
g)
…………
现在问题不能再现了,想问一下有经验的高手,这种异常一般会是什么原因造成的呢? 展开
************** Exception Text **************
System.NullReferenceException:
Object reference not set to an instance of an object.
at
DevExpress.Utils.AppearanceObject.CalcDefaultTextSize(Graphics g)
at
DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSizeCore(GraphicsCache
cache, String text, Int32 maxWidth)
at
DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSizeCore(Graphics g,
String text, Int32 maxWidth)
at
DevExpress.XtraEditors.ViewInfo.BaseControlViewInfo.CalcTextSize(Graphics g,
Boolean useDisplayText)
at
DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo.CalcTextSize(Graphics g,
Boolean useDisplayText)
at
DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo.CalcBestFitTextSize(Graphics
g)
at
DevExpress.XtraEditors.ViewInfo.BaseEditViewInfo.CalcBestFit(Graphics g)
at DevExpress.XtraEditors.ViewInfo.TextEditViewInfo.CalcMinHeightCore(Graphics
g)
…………
现在问题不能再现了,想问一下有经验的高手,这种异常一般会是什么原因造成的呢? 展开
2个回答
展开全部
1,增加新行用InitNewRow事件,给新行某字段赋值。后结束编辑。
private void grdView_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
view.SetRowCellValue(e.RowHandle, view.Columns["EnterID"], this.dS_MEnterStoreView.MEnterStore[0].ID);
this.grdControl.EmbeddedNavigator.Buttons.EndEdit.DoClick();
this.grdView.UpdateCurrentRow();
}
2,如果进行行验证,就在换行时时行,用grdView_FocusedRowChanged事件。
private void grdView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
WsClient.WS_MEnterStore.DS_MEnterStoreView.MEnterDetailRow row = (WsClient.WS_MEnterStore.DS_MEnterStoreView.MEnterDetailRow)this.grdView.GetDataRow(e.FocusedRowHandle);
if (row != null)
{
if ((this.OperState == Common.Enum.TOperState.UnConfirmNew)
|| (this.OperState == Common.Enum.TOperState.UnConfirmEdit))
{
this.InitComboBoxValue(row, row.IsGoodIDNull()?0:row.GoodID, false);
this.InitBatchComboBoxValue(row, row.IsGoodIDNull()?0:row.GoodID, false);
}
}
}
3,如果需要改变行的某一列的同时改变其它的列用grdView_CellValueChanged事件。
private void grdView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (this.grdView.FocusedColumn == e.Column)
{
if (e.Column == this.colAmount)
{
}
}
}
4,如果需在离开行的时候需要验证,则用grdView_BeforeLeaveRow事件。
private void grdView_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
view.SetRowCellValue(e.RowHandle, view.Columns["EnterID"], this.dS_MEnterStoreView.MEnterStore[0].ID);
this.grdControl.EmbeddedNavigator.Buttons.EndEdit.DoClick();
this.grdView.UpdateCurrentRow();
}
2,如果进行行验证,就在换行时时行,用grdView_FocusedRowChanged事件。
private void grdView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
WsClient.WS_MEnterStore.DS_MEnterStoreView.MEnterDetailRow row = (WsClient.WS_MEnterStore.DS_MEnterStoreView.MEnterDetailRow)this.grdView.GetDataRow(e.FocusedRowHandle);
if (row != null)
{
if ((this.OperState == Common.Enum.TOperState.UnConfirmNew)
|| (this.OperState == Common.Enum.TOperState.UnConfirmEdit))
{
this.InitComboBoxValue(row, row.IsGoodIDNull()?0:row.GoodID, false);
this.InitBatchComboBoxValue(row, row.IsGoodIDNull()?0:row.GoodID, false);
}
}
}
3,如果需要改变行的某一列的同时改变其它的列用grdView_CellValueChanged事件。
private void grdView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (this.grdView.FocusedColumn == e.Column)
{
if (e.Column == this.colAmount)
{
}
}
}
4,如果需在离开行的时候需要验证,则用grdView_BeforeLeaveRow事件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询