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. [zz]简单有效,在家就能锻炼!

    简单有效,在家就能锻炼!下面这套动作美腿.美臀.瘦腰,一步到位,是全身塑形的必备,不用多练,每组1分钟.只需一把椅子即可,献给没有时间.条件去健身房的健身爱好者们! http://weibo.com/ ...

  2. SOA 面向服务的体系结构

    SOA:面向服务的体系结构(service-oriented architecture) 是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的接口和契约联系起来. 接口是采 ...

  3. My Demo Reels

    Some elementary algorithms about discrete differential geometry http://www.cnblogs.com/yaoyansi/p/56 ...

  4. JDBC连接实例

    package com.javaee.corejava; import java.sql.Connection; import java.sql.DriverManager; import java. ...

  5. 【学】jQuery的源码思路4——增加一些功能

    本文说一些简单的jQuery实现原理 eq() get() hide() show() index() find() //返回找到的一组元素中的第n个 zQuery.prototype.eq=func ...

  6. oracle之check约束小结

    一下是Ocp考试指导中,对于oracle约束的描述: The constraint types supported by the Oracle database are as follows:UNIQ ...

  7. 关于Maven项目

    用maven 工程搭建项目,在搭建好之后,运行时却抛出了这样的错误:  Error configuring application listener of class org.springframew ...

  8. 新安装loadrunner无法录制脚本的原因之一及解决方案

    eg:IE浏览器 1.新安装的loadrunner录制脚本,一直是加载中的状态: 2.苦思冥想终于找到解决方案: 3.IE浏览器-->设置-->Internet选项 4."安全& ...

  9. Java课程

    链接: http://pan.baidu.com/s/1kU2n3wz 密码: r88d (封装,继承,多态) 1.JDK的安装和配置 2.HelloWorld 3.基本概念 4.数据类型 5.程序控 ...

  10. RMQ 训练 之 codevs 1690 开关灯 已经搞定

    思路 懒标记法  记stop[rt] 表示 rt这个线段树节点的下方儿子们需要被更新几次  记住是下方 量纲不要乱  否则写的一堆渣代码 我的代码里面black是维护黑灯的数量 其实做烦了  如果是维 ...