lesyriad
lesyriad

Reputation: 115

Show ToolTip for DataGridView on KeyDown

So I'm looking for a way to display some help when a key is pressed. I'm thinking the best option is ToolTip. But how can I get it so it shows instantly on KeyDown on a DataGridView? I have the ToolTip setup when KeyDownis pressed. However it doesn't show up for some reason. This is the code in my KeyDown event:

if (e.Control)
{
    if(tt == null)
    {
        tt = new ToolTip();
        tt.InitialDelay = 0;
        tt.Active = true;
        tt.Show("Help Test", dataGridView1.FindForm());
    }           
}

Yet nothing displays when I push down Ctrl.

Upvotes: 1

Views: 281

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125217

You should set this.dataGridView1.ShowCellToolTips = false; using designer or using code, then you can show a manual ToolTip.

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if(e.Control)
        toolTip1.Show("Some help", this.dataGridView1);
}

Note: You should dispose a ToolTip when the form disposes, so it's better to drop a ToolTip component from toolbox on form and use it. This way you don't need to dispose it manually yourself.

Upvotes: 1

Related Questions