473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 1210

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

Similar topics

2
10547
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 Error in '/Cr_Dataset' Application. ----------------------------------------------------------- ---------------------
7
8104
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: private void Page_Load(object sender, System.EventArgs e) { // load content XslTransform trans = new XslTransform();
0
9776
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" AutoPostBackOnNodeMove="false" DragAndDropEnabled="true" NodeEditingEnabled="False" KeyboardEnabled="true" CssClass="TreeView" NodeCssClass="TreeNode" SelectedNodeCssClass="SelectedTreeNode" HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
6
6126
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 then tried to access 2nd, or 3rd, etc page. The problem is it happens sometimes - sometimes when they clicked refresh button, then everything is ok. Now they told me it happens more frequently. but I have tried by myself many times and never got...
3
4229
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 that needs the class module I get an error on web site: Object reference not set to an instance of an object Here is where the error is:
3
2568
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
1
4218
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 Class rightside_portal : Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
6
2220
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 is there any article which can explain it. kalaivanan
1
2747
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 System.Configuration; using System.Collections; using System.Web; using System.Web.Security;
4
2183
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: ==================ERROR================================== Object reference not set to an instance of an object. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.