I'm using winforms ToolTip class on a DataGridView (not tooltip of datagridview since I need custom formatting.)
And I call toolTip.Show() in DataGridView's CellMouseEnter event.
toolTip.Show() shows the the tooltip immediately and InitialDelay property is not working since I called toolTip.Show().
Is there another way to delay toolTip.Show() just like regular initaldelay.
ToolTip Show method shows right away the tooltip text, if you want a delay you have to use SetToolTip instead, being 5000 milliseconds the maximun:
toolTip.InitialDelay = 5000;
toolTip.SetToolTip(dataGridView1, "Max InitialDelay is 5000 milliseconds");
Note: for the above to work properly, remember you first have to disable DataGridView builtin tooltip :
dataGridView1.ShowCellToolTips = false;
EDIT: To show tool tip for each row (and cell).
Note the use of CellMouseEnter and CellMouseLeave events
private ToolTip toolTip;
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.ColumnIndex == -1) return;
var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell.Value != null){
toolTip = new ToolTip();
toolTip.InitialDelay = 3000;
dataGridView1.ShowCellToolTips = false;
toolTip.SetToolTip(dataGridView1, cell.Value.ToString());
}
}
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (toolTip != null)
toolTip.Dispose();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With