要在Winform(C#)的DataGridView控件中实现鼠标移上控件的单元格中时,将其值以Tooltip提示的形式显示出来。这个可以使用CellToolTipTextNeeded事件。设置Datagridview的CellToolTipTextNeeded事件,如下:

 

 private void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
        {
            if (e.ColumnIndex == 0)
                e.ToolTipText = "虚夜宫";
            else if (e.ColumnIndex == 1)
                e.ToolTipText = "Lwolf.cn";
            else
                e.ToolTipText = string.Format("{0}",
                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
        }

 

这个效果在单元格中文字内容过多时是很有用的~~ 

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2021-08-10
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
猜你喜欢
  • 2022-02-18
  • 2021-05-23
  • 2022-01-07
  • 2022-12-23
  • 2022-01-16
  • 2021-05-30
  • 2021-07-14
相关资源
相似解决方案