473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Object reference not set to an instance of an object. in c# using treeview

1
Expand|Select|Wrap|Line Numbers
  1. private void treeView1_DragDrop(object sender, DragEventArgs e)
  2.         {
  3.             // Retrieve the client coordinates of the drop location.
  4.             Point targetPoint = trvDocStyles.PointToClient(new Point(e.X, e.Y));
  5.             TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
  6.             if ((draggedNode.Tag.GetType()) == (typeof(DocStyles)))//error line
  7.                 return;
  8.             // Retrieve the node at the drop location.
  9.             TreeNode targetNode = trvDocStyles.GetNodeAt(targetPoint);
  10.             //TreeNode targetNode = null;
  11.             targetNode = trvDocStyles.GetNodeAt(targetPoint);
  12.             if (targetNode.Tag.GetType() == typeof(DocParas))
  13.             {
  14.                 targetNode = targetNode.Parent;
  15.             }
  16.  
  17.             // Retrieve the node that was dragged.
  18.  
  19.  
  20.             // Confirm that the node at the drop location is not  
  21.             // the dragged node or a descendant of the dragged node. 
  22.             DocStyles targetstyle = objDocStyles.Find(c => c.StyleID == (targetNode.Tag as DocStyles).StyleID);
  23.             DocParas draggpara = objdocpara.Find(c => c.ParaID == (draggedNode.Tag as DocParas).ParaID);
  24.             draggpara.CurentStyleID = targetstyle.StyleID;
  25.  
  26.             int parcnt = 0;
  27.             parcnt = objdocpara.Where(c => c.ParaStyleID == targetstyle.StyleID || c.CurentStyleID == targetstyle.StyleID).Count();
  28.  
  29.             targetNode.Text = (parcnt > 1) ? targetstyle.DispStyleName + " - ( " + parcnt + " )" : targetstyle.DispStyleName;
  30.  
  31.             DocStyles currentstyle = objDocStyles.Find(c => c.StyleID == draggpara.ParaStyleID);
  32.  
  33.  
  34.  
  35.             // Confirm that the node at the drop location is not  
  36.             // the dragged node or a descendant of the dragged node. 
  37.             if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
  38.             {
  39.                 // If it is a move operation, remove the node from its current  
  40.                 // location and add it to the node at the drop location. 
  41.                 if (e.Effect == DragDropEffects.Move)
  42.                 {
  43.                     draggedNode.Remove();
  44.                     targetNode.Nodes.Add(draggedNode);
  45.                 }
  46.  
  47.                 // If it is a copy operation, clone the dragged node  
  48.                 // and add it to the node at the drop location. 
  49.                 else if (e.Effect == DragDropEffects.Copy)
  50.                 {
  51.                     targetNode.Nodes.Add((TreeNode)draggedNode.Clone());
  52.                 }
  53.  
  54.                 // Expand the node at the location  
  55.                 // to show the dropped node.
  56.                 targetNode.Expand();
  57.             }
  58.         }
  59.  
  60.         // Determine whether one node is a parent  
  61.         // or ancestor of a second node. 
  62.         private bool ContainsNode(TreeNode node1, TreeNode node2)
  63.         {
  64.             // Check the parent node of the second node. 
  65.             if (node2.Parent == null) return false;
  66.             if (node2.Parent.Equals(node1)) return true;
  67.  
  68.             // If the parent node is not null or equal to the first node,  
  69.             // call the ContainsNode method recursively using the parent of  
  70.             // the second node. 
  71.             return ContainsNode(node1, node2.Parent);
  72.         }







i am getting an error object reference not set to an instance of an object
Sep 13 '13 #1
0 1187

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
7
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: ...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
3
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object...
1
by: Nathan Sokalski | last post by:
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this UserControl looks like the following: Partial Public...
6
by: kalaivanan | last post by:
hi, i am a beginner in c#. i have theoretical knowledge about object, reference and instance. but i want to know clearly about what is an object, reference and instance. can any one help me? or...
1
by: vishnu | last post by:
Hi, I am working on asp.net project which I converted the code fron VB to C# and instead of RaiseEvent in VB code I used the following code. using System; using System.Data; using...
4
by: livmacca | last post by:
Hi, I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.