2013-08-05 62 views
0

我已經通過設置NullReference異常

DrawMode=OwnerDrawAll; 

即,

OnDrawNode() 

定製樹視圖在C#的.NET的外觀將被覆蓋並繪製的每個節點和連接線成功。除了我經常得到一個NullReference消息外,每件事情都很好。以下是堆棧跟蹤

at System.Windows.Forms.TreeNode.get_Handle() 
at System.Windows.Forms.TreeNode.get_RowBounds() 
at System.Windows.Forms.TreeView.CustomDraw(Message& m) 
at System.Windows.Forms.TreeView.WmNotify(Message& m) 
at System.Windows.Forms.TreeView.WndProc(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
The message send to the WndProc during the exception is "WndProc(ref System.Windows.Forms.Message message = {msg=0x204e (WM_REFLECT + WM_NOTIFY)). 

通常我得到這個例外以下步驟:

  1. 添加2個節點有大量的文字到TreeView。
  2. 將RightToLeft和RightToLeftLayout屬性設置爲true。
  3. 使用「Nodes.Clear()」API刪除所有節點。
  4. 再次在樹視圖中添加2-3個大文本節點。

任何一個有任何想法解決這個?

+0

可以共享代碼,你建的樹? – nhrobin

+0

在某一時間(例如,當窗體是不可見的)添加到'treeview'節點可能會導致此異常。 –

+0

@KingKing表單總是可見的。 – NidhiSree

回答

0

據發現

TreeNode.get_Handle() 

有關自定義繪製通知期間拋出空引用異常。我沒有得到例外的理由。但是我已經在處理「NM_CUSTOMDRAW」 通知信息中的空引用異常解決它。

相關問題