question

youki avatar image
0 Votes"
youki asked DanielZhang-MSFT commented

Gridview cell tooltip flickers

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

dotnet-csharpwindows-forms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @youki,
May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.
Best Regards,
Daniel Zhang

0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

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.



813.gif (79.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.