DevExpress使用笔记

1. 隐藏GridView的FilterPanel

gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;

2. GridView添加鼠标双击数据行的事件

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)
    {
    ......
    }
}

3. GridView列邦定的字段名为一个类名情况下,此列不能分组的解决办法

当FieldName邦定的是一个类的情况下,此类要实现ToString()方法,但此种情况下,GridView不能基于此类进行分组。解决办法为,将FeildName邦定为类名.Name (Name为邦定类的一个String的属性)

4. GridView数据修改后,手动提交

gridView.CloseEditor();
gridView.UpdateCurrentRow();

5. 继承后窗体中的DevExpress控件无法修改的解决办法

Visual Studio 菜单:DevExpress --> WinForms Controls V** --> Change Design-Time Settings...,选中Enable visual...,如下图所示233333_4qT2_2426875.jpg

然后重新启动Visual Studio

6. LookUpEdit支持多列查找

重新写一个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);
}


7. Search values against multiple columns in GridLookupEdit

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();
}


8. in the CustomGridPainter.DrawRowCell method

cell.ViewInfo.MatchedStringUseContains = false;

9. LookUpEdit控件处理新值时候,要注意的问题

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

10. 解决GridControl在绑定实体类列表时不能分组

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
}


11. XtraReport打印本地Report文件(V15)

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();
}


转载于:https://my.oschina.net/fdstudio/blog/527113

================================== ==注意:一共2个压缩包,这是第2个== ================================== *提示:无自动安装程序,包含所有源码、例子、帮助,请按照安装顺序安装!!! New Features in 13.1.4 (VCL Product Line) Breaking Changes To learn about breaking changes in this version, please refer to the following page: Breaking Changes in 13.1.4 (VCL Product Line) Known Issues To learn about known issues in this version, please refer to the following page: Known Issues in 13.1.4 (VCL Product Line) The following sections list all minor and major changes in DevExpress VCL 13.1.4. Note that products, controls and libraries which aren't mentioned in the list below are included in the unified installer for compatibility, but have not been updated. Enhancements and Updates New Features/Updates VCL Subscription ExpressTile Control ExpressDataController Resolved Issues ExpressBars Suite ExpressLayout Control ExpressNavBar ExpressPageControl ExpressPivotGrid Suite ExpressPrinting System ExpressQuantumGrid Suite ExpressQuantumTreeList Suite ExpressScheduler Suite ExpressSkins Library ExpressSpreadSheet ExpressTile Control ExpressVerticalGrid Suite ExpressDataController ExpressEditors Library ExpressLibrary Installation (VCL) New Features/Updates VCL Subscription S170932 - Documentation - Describe that the ExpressLayout Control and ExpressDocking Library are incompatible ExpressTile Control S172299 - Center the Back button and title text vertically within the title Common Libraries ExpressDataController S172107 - Add the capability to disable multi-threaded operations at the level of custom data sources (TcxCustomDataSource descendants) Resolved Issues ExpressBars Suite Q476901 - Documentation - The "Ribbon Application Menu" topic does not contain the menu creation steps that are specific to TdxRibbonBackstageView Q452658 - Documentation - The TdxCustomRibbonGalleryItem.GalleryGroups property is not marked as deprecated and is used in topics instead of TdxCustomRibbonGalleryItem.GalleryCategories Q513198 -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值