question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataGridView: sporadic NullReferenceException when trying to display the tooltip

See original GitHub issue

.NET version

.NET version: 6.0.300 Windows version: Windows 7 using classic theme

Did it work in .NET Framework?

I’m not 100% sure whether it works in .NET Framework but I did not face this issue earlier.

Issue description

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.Control.GetSafeHandle(IWin32Window window)
   at Interop.ComCtl32.ToolInfoWrapper`1..ctor(T handle, TTF flags, String text)
   at System.Windows.Forms.ToolTip.TryGetBubbleSize(IKeyboardToolTip tool, Rectangle toolRectangle, Size& bubbleSize)
   at System.Windows.Forms.ToolTip.ShowKeyboardToolTip(String text, IKeyboardToolTip tool, Int32 duration)
   at System.Windows.Forms.KeyboardToolTipStateMachine.ShowToolTip(IKeyboardToolTip tool, ToolTip toolTip)
   at System.Windows.Forms.KeyboardToolTipStateMachine.Transition(IKeyboardToolTip tool, ToolTip tooltip, SmEvent event)
   at System.Windows.Forms.KeyboardToolTipStateMachine.Transit(SmEvent event, IKeyboardToolTip source)
   at System.Windows.Forms.KeyboardToolTipStateMachine.<SetupInitShowTimer>b__25_0(Timer sender)
   at System.Windows.Forms.KeyboardToolTipStateMachine.<>c__DisplayClass27_0.<GetOneRunTickHandler>g__wrapper|0(Object sender, EventArgs eventArgs)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

Steps to reproduce

It occurs randomly (up to a couple of times per day) at one of my customer’s computer who uses Windows 7 with visual styles disabled (classic theme).

The DataGridView is rapidly updated via its DataSource (in every 100ms). It does not have any tooltip configured so it must be the default tooltip when the cell is too small to be able to display the entire text.

I apologize for not being able to provide a more specific reproduction but please refer to the provided strack trace, which clearly indicates that some handle must be invalid in the ToolInfoWrapper<T> constructor when the size of the tooltip is attempted to be determined.

I could never reproduce it locally maybe because I use Windows 10.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
merriemcgawcommented, Mar 9, 2023

@koszeggy I’m glad you were able to find a solution. @Amy-Li03 thanks for all the repro tries 😄 . I am going to close the issue as there is no action to take at this point on our side.

1reaction
merriemcgawcommented, Feb 28, 2023

@Olina-Zhang can your team try to reproduce this in .NET 8 with using keyboard navigation in a full DGV? The specific thing I’m interested in is the keyboard scrolling through the DataGridView.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullReferenceException with ToolTip.CreateHandle
I just ran into the same problem. It seems the exception is thrown from within the ToolTip.CreateHandle() method and it happens on MDI...
Read more >
Add ToolTips to Individual Cells in DataGridView Control
By default, ToolTips are used to display the values of DataGridView cells that are too small to show their entire contents.
Read more >
Column Validation in Blazor DataGrid Component
Column validation allows you to validate the edited or added row data and it display errors for invalid fields before saving data. DataGrid...
Read more >
Time series | Grafana documentation
When you hover your cursor over the visualization, Grafana can display tooltips. Choose how tooltips behave. Single - The hover tooltip shows only...
Read more >
[Solved]-Datagridview Cell ToolTip Delay Time-C#
I found why DataGridView_CellEnter event called several times. When Tooltip shows up over the cell (location based on cell rectangular) mouse pointer stays...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found