{
string regid = this.gridView1.GetRowCellValue(e.RowHandle, \string regName = this.gridView1.GetRowCellValue(e.RowHandle, \if ( regid.Length < 1) {
e.Valid = false;
this.gridView1.SetColumnError(this.gridView1.Columns[\\请填写区划编号!\DevExpress.XtraEditors.DXErrorProvider.ErrorType.Default); // e.ErrorText = \区划名称不能为空!\ }
if (regName.Length < 1)
{ e.Valid = false;
this.gridView1.SetColumnError(this.gridView1.Columns[\\区划名称不能为空!\ } } private
void
gridView1_InvalidRowException(object
sender,
DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs e) {
if (e.RowHandle >= 0) {
if (this.gridView1.GetRowCellValue(e.RowHandle, this.gridView1.Columns[\== \|| this.gridView1.GetRowCellValue(e.RowHandle,
this.gridView1.Columns[\ {
if (MyDialog.Alert(\ 您所填写的内容不符合规则\\n 要放弃您刚才对此项所做的更改吗?\\您所编辑的内容不符合规则\MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
e.ExceptionMode = ExceptionMode.Ignore; } else
{
e.ExceptionMode = ExceptionMode.NoAction; } } } else {
e.ExceptionMode = ExceptionMode.Ignore;
} }
如果数据源中只包含图片的链接,如何在DevExpress GridControl的一列中显示外部图片?
要实现该功能,可通过非绑定列的方式来实现。具体实现方法如下:
1. 创建了一个非绑定列并设置其相应的属性,属性设置如下:
l FieldName设为 Image (该字段名必须是唯一的)
l UnboundType设为 UnboundColumnType.Object
l ColumnEdit设为RepositoryItemPictureEdit类的实例(该操作PictureEdit 为该列的内置编辑器)
2. 处理View的CustomUnboundColumnData事件,用于为非绑定列填充数据。在该事件中需加载图片,将其存放在一个hashtable中,然后再将其提供给对应的单元格。
关键代码:
//获取文件路径
string GetFileName(string color) {
if(color == null || color == string.Empty)
return string.Empty;
return color + \
}
//处理CustomUnboundColumnData事件,为非绑定列填充数据
private void gridView1_CustomUnboundColumnData(object DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) {
if(e.Column.FieldName == \
GridView view = sender as GridView;
sender,
string colorName = (string)((DataRowView)e.Row)[\
string fileName = GetFileName(colorName).ToLower();
if(!Images.ContainsKey(fileName)) {
Image img = null;
try {
string filePath = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, ImageDir + fileName, false);
img = Image.FromFile(filePath);
}
catch {
}
Images.Add(fileName, img);
}
e.Value = Images[fileName];
}
}
怎样给DevExpress XtraTreeList添加行的序号? private void treeList1_CustomDrawNodeIndicator(object DevExpress.XtraTreeList.CustomDrawNodeIndicatorEventArgs e)
{
TreeList tree = sender as DevExpress.XtraTreeList.TreeList;
IndicatorObjectInfoArgs args = e.ObjectArgs as IndicatorObjectInfoArgs;
args.DisplayText = (tree.GetVisibleIndexByNode(e.Node) + 1).ToString();
sender,
}
怎样在DevExpress XtraTreeList中设置ToolTip?
您可以使用ToolTipController控件,然后通过ToolTipController.GetActiveObjectInfo事件来设置ToolTip 关键代码: private
{
if (e.SelectedControl is DevExpress.XtraTreeList.TreeList)
{
TreeList tree = (TreeList)e.SelectedControl;
TreeListHitInfo hit = tree.CalcHitInfo(e.ControlMousePosition);
if (hit.HitInfoType == HitInfoType.Cell)
{
object cellInfo = new TreeListCellToolTipInfo(hit.Node, hit.Column, null);
string toolTip = string.Format(\(Column: {1}, Node ID: {2})\hit.Node[hit.Column],
hit.Column.VisibleIndex, hit.Node.Id);
e.Info = new DevExpress.Utils.ToolTipControlInfo(cellInfo, toolTip);
}
} }
DevExpress XtraGrid的功能实在强大,刚使用的时候看到一大片属性设置,分不清东南西北,参照demo和使用中的一些经验,记录一下使用方法。
1、 数据绑定(IList)
void
toolTipController1_GetActiveObjectInfo(object
sender,
DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
DevExpress.XtraGrid.Views.Grid.GridView gridView1; IList
list.Add(B); ………..
gridControl1.DataSource = list;
2、 在Grid上编辑数据
修改属性gridView1.OptionsView.NewItemRowPosition,设为Top或Bottom可以在Grid上添加数据。
(在demo中原文:a record object must be inherited from the IEditableObject class if you need the ability to cancel newly added records via the grid)
译:如果你需要通过gird取消新建的记录,你的记录对象必须实现IEditableObject
(注:在测试中,感觉不需要继承IEditableObject,在grid编辑后也能实现取消。demo通过实现IEditableObject的BeginEdit、CancelEdit方法,数据编辑后恢复特定数据。不使用grid直接修改数据,可以考虑这种恢复原数据的方法。)
3、 修改列(Column)格式
DevExpress.XtraGrid.Columns.GridColumn col = gridView1.Columns[0];数据对齐方式 col.AppearanceCell.TextOptions.HAlignment, 默认值Default,可选值Default/Near/Center/Far。 说明:以下情况是基于从左到右的文字排列;若是从右到左,用法相反。 Default:数据默认的对齐方式 Near:左对齐 Center:居中对齐 Far:右对齐
列标题 col.Caption
对应绑定数据的属性 col.FieldName 排列顺序 col.VisibleIndex 格式化显示数据
Col.DisplayFormat.FormatType Col.DisplayFormat.Format
Col.DisplayFormat.FormatString
区别:FormatType/FormatString 使用当前系统的语言区域设置,Format使用特定的[url=ms-help://MS.VSCC.v80/MS.VSIPCC.v80/DevExpress.NETv8.2/
DevExpress.XtraData/DevExpressUtilsFormatInfo_FormatTypetopic.htm##]