473,699 Members | 2,822 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 1208

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

Similar topics

2
10545
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
8099
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
9774
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
6120
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
4222
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
2566
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
4215
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
2216
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
2743
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
2182
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
8704
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
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
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...
1
8939
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8895
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
7778
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5879
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
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.