1

I'm working in C# in Visual Studio. I have a DataGridView with a large amount of data (i.e 100+ columns, 1000+ rows). I've set the DataGridView to be double buffered and the user interaction and scrolling are working well. My DataGridView is called "ws" in the code below:

typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, ws, new object[] { true });

Now, I'm trying to add tool tips that are dependent on the contents of the cells. I set up a DataGridViewCellToolTipTextNeededEventHandler, but the tool tips only show intermittently.

When the DataGridView first loads, the tool tips show fine. If I scroll slowly down, the tool tips show fine. However, if I grab the scroll bar and move quickly to the middle or bottom of the grid, the tool tips stop working. Scrolling back up to the top of the grid restores the tool tip functionality.

Here is my code for setting the tool tips:

    this.ws.CellToolTipTextNeeded += new System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler(ws_cellToolTipTextNeeded);


    private void ws_cellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
    {
        if (e.RowIndex < 0 || e.ColumnIndex > 1) return;  // only want tool tips on 0th and 1st column
        String rowType = ws.Rows[e.RowIndex].Cells[0].Value.ToString().ToUpper();
        e.ToolTipText = toolTip(rowType);
    }

In my code, toolTip(rowType) is a function that returns a String based on the type of row which is defined in the 0th column.

I've tried turning off the double buffering, but the problem remains. Not sure what else to investigate.

Thoughts/Suggestions? Mike

Mike Paisner
  • 171
  • 1
  • 7
  • I see 4 possibilities: 1. The DGV isn't raising `CellToolTipTextNeeded` after a certain point; 2. The handler is erroring out but not reporting it; 3. `e.RowIndex` or `e.ColumnIndex` are at some point out of range; 4. So many events are being processed that it hasn't gotten around to the ones from whatever row you stopped at. – Ann L. Jul 05 '20 at 18:41
  • It would be interesting to put a `Debug.WriteLine` statement in the handler and look at the output as you do your scroll-down experiment, to see whether the event isn't being called, or it's being called so many times that it's backed up! – Ann L. Jul 05 '20 at 18:42
  • Those are my thoughts and suggestions at this time. – Ann L. Jul 05 '20 at 18:43
  • @AnnL.-Added a debug line (`Console.WriteLine(e.ToolTipText);`) at the end of the ws_cellToolTipTextNeeded event function and the debug line was written in both scenarios - i.e. when tool tip is displayed near top of grid and when tool tip is not displayed at middle or bottom of grid. Debug line is after `e.ToolTipText = toolTip(rowType);` line and I'm not seeing any errors. I think that eliminates possibilities 1-3. Is there anything that can be done about possibility 4? – Mike Paisner Jul 05 '20 at 20:40
  • The issue only seems to occur on large grids. I can scroll on smaller grids and tool tips show up reliably. Don't know how to isolate the issue or how to solve it. – Mike Paisner Jul 05 '20 at 22:06
  • Just out of curiosity: Can you scroll down, wait a few minutes, and then see if the tooltip will show up? Wondering what will happen if you give it time to catch up (assuming that's the problem.) – Ann L. Jul 06 '20 at 12:21
  • It doesn't sound like a problem with your code. I'm wondering if it's a reported problem with the DataGridView. – Ann L. Jul 06 '20 at 12:37
  • Timing doesn't seem to be contributing to the issue. I let it sit for 30 minutes and tool tip still doesn't display at the bottom of the grid. Issue seems to be driven by the location on the grid. Tool tip displays reliably at the top of the grid. However, if I go far enough down the grid, I get to a point where the tool tip stops displaying. Scroll up a bit in the grid and it works fine. No errors displayed in console output. This might have to become a known issue in my application => Tool Tips may not display in large grids. :( – Mike Paisner Jul 06 '20 at 18:21

0 Answers0