前提: SelectionMode 设置成了 FullColumnSelect我这样写的 :
        public void DataGridViewSelectCells(DataGridView dgv, ToolTip toolTip)
        {
            toolTip.RemoveAll();
            string title = "";
            title = dgv.CurrentCell.Value.ToString();            dgv.ShowCellToolTips = false;            toolTip.ToolTipIcon = ToolTipIcon.Info;
            toolTip.ToolTipTitle = "鼠标选定信息:";
            toolTip.IsBalloon = true;//气球形状  
            toolTip.UseAnimation = true;
            toolTip.AutoPopDelay = 10000;
            toolTip.InitialDelay = 500;
            toolTip.ReshowDelay = 500;
            toolTip.RemoveAll();            toolTip.SetToolTip(dgv, title);
        }        private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridViewSelectCells(dataGridView1, toolTip);
        }不行 不知道该怎么弄? 求教!!!

解决方案 »

  1.   

    DataGridView 单元格自身就有 ToolTip
    dataGridView1.Rows[0].Cells[0].ToolTipText = ...
      

  2.   

    我知道 可是它自己的tooltip 如果文字很多的话 会占满全屏的宽度 我想把这个tooltip去掉自己加一个 可以控制 提示框的大小
      

  3.   

    dataGridView1.ShowCellToolTips = true;,这样显示不全的文字,就会自动提示
      

  4.   

    用 CellMouseEnter 事件,代码稍微修改下
    public void DataGridViewSelectCells(DataGridView dgv, ToolTip toolTip, string value)
    {
        dgv.ShowCellToolTips = false;    toolTip.ToolTipIcon = ToolTipIcon.Info;
        toolTip.ToolTipTitle = "鼠标选定信息:";
        toolTip.IsBalloon = true;//气球形状   
        toolTip.UseAnimation = true;
        toolTip.AutoPopDelay = 10000;
        toolTip.InitialDelay = 500;
        toolTip.ReshowDelay = 500;
        toolTip.RemoveAll();    toolTip.SetToolTip(dgv, value);
    }private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
    {
        DataGridViewSelectCells(dataGridView1, toolTip, dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());
    }
      

  5.   

    有个错误
    索引超出范围。必须为非负值并小于集合大小。
    参数名: index
      

  6.   

    事件方法
    private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
    {
        if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
        {
            var v = dataGridView1[e.ColumnIndex, e.RowIndex].Value;
            DataGridViewSelectCells(dataGridView1, toolTip, v != null ? v.ToString() : null);
        }
    }
      

  7.   

    你好,你这个不要用CellMouseEnter事件,麻烦,用他自带的另一个事件:
      //提示信息
            private void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
            {
                e.ToolTipText = "当前名称:" + this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            }
      

  8.   


    可以帮我看下这个帖子吗 谢谢
    http://topic.csdn.net/u/20120613/18/8d5758ca-6ba2-43ab-8eef-197980c05576.html