winforms Tooltip in winforms DataGridViewImageColu

2020-08-01 05:46发布

问题:

I have the following code that successfully displays an image in its column based on its bound DataProperty:

  private void dgvTasks_CellFormatting( object sender, DataGridViewCellFormattingEventArgs e ) {
        if (dgvTasks.Columns[e.ColumnIndex] is DataGridViewImageColumn && e.ColumnIndex == 1) {
            e.Value = ( (bool)e.Value == true ) ? Properties.Resources.ok : Properties.Resources.clock;
        }
  }

but I would like to know how its possible to show a tooltip when a user hovers over the image?

回答1:

generally if you have row & column for a cell, you can set a ToolTipText using:

dataGridView1.Rows[rowIndex].Cells[columnIndex].ToolTipText = "..."

and in your case, you have e.RowIndex and e.RowIndex:

dgvTasks.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = "..."