问题
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 = "..."
来源:https://stackoverflow.com/questions/1561119/winforms-tooltip-in-winforms-datagridviewimagecolumn