Gridview cell tooltip flickers

youki 996 Reputation points
2021-08-12T13:42:26.593+00:00

Hello,
The default tool tip of a gridview cell isn't displayed long enough.
I tried a few solutions and almost all events but it's still flickering.
I solved it with the following code but then it doesn't appear in special situations (appears only for a few milliseconds). May be if i'm too fast with the mouse?!

I also wanted to show the tooltip only, if the cell text is truncated like in the default behaviour but is there an easy solution without measuring?

            _toolTip = new ToolTip();
            //_toolTip.AutomaticDelay = 100;
            _toolTip.AutoPopDelay = 30000;
            //_toolTip.ReshowDelay = 100;
            gvRightButton.ShowCellToolTips = false;

private static DataGridViewCell ccell;

    private void gvTest_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
    {
        var cell = gvTest.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (e.ColumnIndex >= 1 & e.RowIndex >= 0 && cell != ccell)
        {
            ccell = cell;
            _toolTip.Show(gvTest.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), gvTest, 30000);
        }
    }

    private void gvTest_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
    {
        if (!string.IsNullOrEmpty(_toolTip.GetToolTip(gvTest)))
        {
            _toolTip.Hide(gvTest);
        }
    }

Regards

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,857 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,383 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2021-08-13T07:14:09.39+00:00

    Hi youki,
    Maybe you can try to use ToolTip.SetToolTip() method.
    Please refer to the following code:

    ToolTip _toolTip;  
    public Form1()  
    {  
        InitializeComponent();  
            _toolTip = new ToolTip();  
        _toolTip.AutoPopDelay = 30000;  
        dataGridView1.ShowCellToolTips = false;  
        _toolTip.ShowAlways = true;  
        _toolTip.InitialDelay = 1000;  
        _toolTip.ReshowDelay = 500;  
    }  
    private int cellColumnIndex = -1;  
    private int cellRowIndex = -1;  
    private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)  
    {  
      
               
      
        if (e.ColumnIndex != cellColumnIndex || e.RowIndex != cellRowIndex)  
        {  
            this._toolTip.Hide(this.dataGridView1);  
            cellColumnIndex = e.ColumnIndex;  
            cellRowIndex = e.RowIndex;  
            if (cellColumnIndex >= 0 && cellRowIndex >= 0)  
            {  
                this._toolTip.SetToolTip(this.dataGridView1, this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());  
            }  
        }  
    }  
    

    The result:
    122974-813.gif
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments