DevExpress.XtraGrid.GridControl 控件默认的tooltip显示的每一个单元格的文本值,但是实际工作中会出现各种需求。我这里就有一个列是折扣率显示的值是0-1之间的两位小数,比如说0.55想要显示成五五折。那就需要自己来做一下处理了(效果看下图)

首先。在工具栏中找到ToolTipControllerk控件,并且设置GridControl.ToolTipController=MainGvTool

            

然后再添加的ToolTipControllerk控件的GetActiveObjectInfo事件中:

private void MainGvTool_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
GridHitInfo hitInfo = gvDiscountSchme.CalcHitInfo(e.ControlMousePosition); if (hitInfo.RowHandle < 0 || hitInfo.Column == null||hitInfo.HitTest != GridHitTest.RowCell)
{
MainGvTool.HideHint();
return;
} DataRow row = gvDiscountSchme.GetDataRow(hitInfo.RowHandle);
    //如果是DiscountRate列 就显示自定义的tooltip
if (hitInfo.Column.FieldName == "DiscountRate")
{
int rate = (int)(Convert.ToDouble(row["DiscountRate"].ToString()) * 100);
e.Info = new ToolTipControlInfo("我也不知道这个参数干嘛用的", GetChineseRate(rate));
}
} private ToolTipControllerShowEventArgs CreateShowArgs(string tooltipText)
{
    ToolTipControllerShowEventArgs args = MainGvTool.CreateShowArgs();
    args.ToolTip = tooltipText;
    return args;
}

 e.Info = new ToolTipControlInfo("我也不知道这个参数干嘛用的", GetChineseRate(rate));的第二个参数就是想要显示的文本,如果把GetChineseRate(rate)换成"aaaa" 那么鼠标移动到Grid上面的 DiscountRate列的时候,tooltip就显示的是"aaaa".

这个功能到这里本来算是完成了,但是我这里是想要把0.55显示成五五折,所以还需要做个处理,这里一并说一下我的实现方式

        Dictionary<int, string> ChineseRateDic = new Dictionary<int, string>();
public FrmDiscountSchemeList()
{
InitializeComponent();
ChineseRateDic = GetRateDis();
} /// <summary>
/// 根据数字获取汉字
/// </summary>
/// <param name="intRate"></param>
/// <returns></returns>
string GetChineseRate(int intRate)
{
string chineseRate = string.Empty; chineseRate=ChineseRateDic.Where(item => item.Key == intRate).First().Value;
return chineseRate;
} /// <summary>
/// 获取1-100数字转换汉字的字典集合
/// </summary>
/// <param name="intRate"></param>
/// <returns></returns>
Dictionary<int, string> GetRateDis()
{
Dictionary<int, string> dic = new Dictionary<int, string>(); for (int i = 1; i <= 100; i++)
{
if (i < 10)
{
dic.Add(i, string.Format("零{0}折", Enum.GetName(typeof(NumToChinese), i)));
}
else if (i >= 10 && i < 100)
{
string tmp = string.Empty;
foreach (char c in i.ToString())
{
if (c.ToString() == "0") break;
tmp += Enum.GetName(typeof(NumToChinese), Convert.ToInt32(c.ToString()));
}
dic.Add(i, string.Format("{0}折", tmp));
}
else
{
dic.Add(i,"不打折");
}
}
return dic;
} /// <summary>
/// 汉字、数字对比枚举
/// </summary>
enum NumToChinese
{
零 = 0,
一 = 1,
二 = 2,
三 = 3,
四 = 4,
五 = 5,
六 = 6,
七 = 7,
八 = 8,
九 = 9
}

DevExpress.XtraGrid.GridControl 实现自定义tooltip的更多相关文章

  1. DevExpress.XtraGrid.GridControl中数据源的绑定问题

    在利用DevExpress.XtraGrid.GridControl作为一个可编辑的表格控件时,在利用控件之前,先将一个初始化的DataTable对象作为GridControl的数据源进行绑定.可是在 ...

  2. 实现在DevExpress.XtraGrid.GridControl的列头绘制复选框以实现全选的功能

    首先新建一个Win Form测试项目,拖一个GridControl控件到窗体上. public partial class Form1 : Form { public Form1() { Initia ...

  3. [转]DevExpress.XtraGrid.GridControl gridView自动列宽代码

    gridView1.OptionsView.ColumnAutoWidth = false;   for (int I = 0; I < gridView1.Columns.Count; I++ ...

  4. DevExpress之GridControl控件小知识

    DevExpress之GridControl控件小知识 一.当代码中的DataTable中有建数据关系时,DevExpress 的 GridControl 会自动增加一个子视图 .列名也就是子表的字段 ...

  5. DevExpress的GridControl的实时加载数据解决方案(取代分页)

    http://blog.csdn.net/educast/article/details/4769457 evExpress是一套第三方控件 其中有类似DataGridView的控件 今天把针对Dev ...

  6. DevExpress.XtraGrid winform试用分享

    DevExpress.XtraGrid在winform里使用还挺麻烦,为了减少重复代码和代码复用,本人针对DevExpress.XtraGrid封装了一个Form的基类,其中涵盖了DevExpress ...

  7. C# DevExpress 的gridControl或gridView数据导出失败解决方法

    来自:http://blog.csdn.net/lybwwp/article/details/8049464 谢谢 在使用DevExpress 的GridPanel控件的时候出现了一个莫名其妙的现象, ...

  8. DevExpress.XtraGrid

    DevExpress.XtraGrid控件使用 该控件类是一个表格控件,但是其具有很多方便而使用的功能,例如可以对记录进行分组,可以再记录的前面加上checkbox,可以将具有相同值的cell 进行合 ...

  9. DevExpress.XtraGrid 【转】

    http://www.cnblogs.com/zeroone/p/4574539.html DevExpress.XtraGrid控件使用 该控件类是一个表格控件,但是其具有很多方便而使用的功能,例如 ...

随机推荐

  1. 最近发现了个js传图预览的函数和大家分享下

    由于浏览器js沙箱,存在不同域,js无法直接调用电脑文件.在之前做传图预览的时候,基本的思路就是, 将图片先保存到服务器中缓存,然后返回一个服务器路径,并显示出图片,然而这样很耗缓存目录文件的.方法也 ...

  2. javascript工具函数

    第一部分 JavaScript工具函数 转义特殊字符为html实体   HtmlEncode: function(str){ return str.replace(/&/g, '&') ...

  3. 【SFTP】使用Jsch实现Sftp文件下载-支持断点续传和进程监控

    参考上篇文章: <[SFTP]使用Jsch实现Sftp文件下载-支持断点续传和进程监控>:http://www.cnblogs.com/ssslinppp/p/6248763.html  ...

  4. c# winform 窗体起始位置 设置

    窗体起始位置为顶部中间,WinForm居中显示: ; ; this.StartPosition = FormStartPosition.Manual; //窗体的位置由Location属性决定 thi ...

  5. 关于Exception

    Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]"   1.java.lang ...

  6. oracle V$SESSION各个字段的含义

    源地址:https://zhidao.baidu.com/question/345549929.html SADDR - session addressSID - session identifier ...

  7. highcharts去掉右下角highchart.com和右上角的图标(三个小横杆)

    去除右下角highchart.com credits: {                enabled:false            } 去除右上角图标 exporting: {         ...

  8. 浏览器缓存相关的Http头介绍:Expires,Cache-Control,Last-Modified,ETag

    转自:http://www.path8.net/tn/archives/2745 缓存对于web开发有重要作用,尤其是大负荷web系统开发中. 缓存分很多种:服务器缓存,第三方缓存,浏览器缓存等.其中 ...

  9. Doxygen给C程序生成注释文档

    近段时间,一直在学习华为C语言编程规范(2011版),在“注释”这一章中发现了一种“Doxygen”的注释转文档工具,查看诸多相关资料,并进行编程实践,终于可以利用Doxygen给C程序生成注释文档. ...

  10. fdfdfdfdfdfdfdfdfdfdfd

    len := Length( Face[integer(FaceType)][Line-1] );  SetLength( Face[integer(FaceType)][Line-1], Len+1 ...