private void gridView1_DoubleClick(object sender, EventArgs e) { GridView detailGrid = (sender as GridView); GridHitInfo hitInfo = (detailGrid.CalcHitInfo((e as MouseEventArgs).Location); if (hitInfo.InRow || hitInfo.InRowCell) { ...... } }
当FieldName邦定的是一个类的情况下,此类要实现ToString()方法,但此种情况下,GridView不能基于此类进行分组。解决办法为,将FeildName邦定为类名.Name (Name为邦定类的一个String的属性)
gridView.CloseEditor(); gridView.UpdateCurrentRow();
Visual Studio 菜单:DevExpress --> WinForms Controls V** --> Change Design-Time Settings...,选中Enable visual...,如下图所示
然后重新启动Visual Studio
重新写一个LookUpEdit控件MyLookUpEdit,继承LookUpEdit,主要是处理拼音过滤的。然后在自己的代码中运用这个重写的控件进行布局和操作
重写MyLookUpEdit控件的同时,也要重写RepositoryItemLookUpEdit控件MyRepositoryItemLookUpEdit,主要是重写RepositoryItemLookUpEdit控件的LookUpListDataAdapter方法去处理拼音过滤,如下代码:
protected override LookUpListDataAdapter CreateDataAdapter() { return new MyLookUpListDataAdapter(this); }
重写LookUpListDataAdapter这个类的CreateFilterExpression方法,在这里面处理用like方式进行拼音过滤
public class MyLookUpListDataAdapter : LookUpListDataAdapter { public MyLookUpListDataAdapter(RepositoryItemLookUpEdit item) : base(item) { } protected override string CreateFilterExpression() { if (string.IsNullOrEmpty(FilterPrefix)) return string.Empty; //判断是否为全部汉字,可以通过自己写一个汉字和拼音转换,判断的类来处理。 bool isAllChinese= PinYinHelper.IsAllChinese(FilterPrefix); string likeClause = DevExpress.Data.Filtering.Helpers.LikeData.CreateStartsWithPattern(FilterPrefix); if (!isAllChinese) { likeClause = PinYinHelper.GetPYString(likeClause); } return new BinaryOperator( isAllChinese ? FilterField : "PINYIN" + FilterField, "%" + likeClause + "%", BinaryOperatorType.Like).ToString(); } }
重写的MyLookupEdit控件里面,要重写
protected override void CreateRepositoryItem() { //这里原文是有此代码,但dx11中edit.SetOwnerEdit方法,外部是不能访问的,感觉下面代码可以删除掉 MyRepositoryItemLookUpEdit edit = new MyRepositoryItemLookUpEdit(); this.fProperties = edit; edit.SetOwnerEdit(this); }
protected override string OnCreateLookupDisplayFilter(string text, string displayMember) { List<CriteriaOperator> subStringOperators = new List<CriteriaOperator>(); foreach (string sString in text.Split(' ')) { string exp = LikeData.CreateStartsWithPattern(sString); List<CriteriaOperator> columnsOperators = new List<CriteriaOperator>(); FunctionOperatorType opType = FunctionOperatorType.StartsWith; foreach (GridColumn col in Columns) { if(col.Visible && col.ColumnType == typeof(string)) { FunctionOperator fo = new FunctionOperator(opType, new OperandProperty(col.FieldName), sString); columnsOperators.Add(fo); } } subStringOperators.Add(new GroupOperator(GroupOperatorType.Or, columnsOperators)); } return new GroupOperator(GroupOperatorType.And, subStringOperators).ToString(); }
in the CustomGridPainter.DrawRowCell method
cell.ViewInfo.MatchedStringUseContains = false;
LookUpEdit的ProcessNewValue事件中,不能重新绑定数据源,否则会报错。解决办法是手工把新增的数据添加到数据源中
private void processNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e) { if(e.DispalyValue == null || string.Empty.Equals(e.DisplayValue)) return; object newValue = //添加新值的处理过程,如弹出添加窗体,然后返回新增加的值 if(newValue != null) { //edit为lookupedit (edit.DataSource as List<绑定的实体类>).Add(newValue); eidt.EditValue = newValue; e.Handled = true; } else { edit.EditValue = null; e.Handled = false; } }
注意DataSource不能转换为List<object>,否则返回null
public class M_User { public int ID {get;set;} public string Name {get;set;} public M_Role Role {get;set;} public override ToString() { return this.Name; } } public class M_Role { public int ID {get;set;} public string Name {get;set;} public override ToStirng() { return this.Name(); } }
如果我们绑定GridControl的DataSource 为 List<M_User>,那么GridView不能对Role字段进行分组,解决办法是M_Role实现IComparable接口
public class M_Role:IComparable { public int ID {get;set;} public string Name {get;set;} public override ToStirng() { return this.Name(); } #region IComparable Members public int CompareTo(object obj) { M_Role role = obj as M_Role; if(role == null) return 0; return String.Compare(role.ID.ToString(), role.ID.ToString()); } #endregion }
string fullFileName = Application.StartupPath + @"\reports\" + fileName; XtraReport report = new XtraReport(); report.LoadLayout(fullFileName); //必须先调用,如果放在report.Parameters.Add() 后面会清空参数 report.Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()); report.Parameters[0].Name = "P1"; report.Parameters[0].Value = "参数1"; report.DataSource = ....; //直接打印 using(ReportPrintTool rt = new ReportPrintTool(report)) { rt.Print(); } //打印预览 using (ReportPrintTool rt = new ReportPrintTool(report)) { rt.AutoShowParametersPanel = false; rt.ShowPreviewDialog(); } //报表设计,套打时调整报表 using (ReportDesignTool rt = new ReportDesignTool(this.Report)) { rt.ShowDesignerDialog(); }