Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System.ArgumentException Assistance Needed... [modified]

System.ArgumentException Assistance Needed... [modified]

Scheduled Pinned Locked Moved C#
questionhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new_phoenix 0
    wrote on last edited by
    #1

    Hello, guys!! I am working with an application that uses a try-catch block inside a DragOver Event handler. The problem is that there is an Argument Exception that occurs when a control is dragged. Technically, it is a circular reference. When this Argument Exception occurs, both controls disappear, and the ArgumentException handler catches the error. The question is, how do I get the Exception handlers to prevent the code from running, thereby preventing the controls from disappearing? Is there a way of trapping the condition that causes the ArgumentException so that the controls would not disappear because of the error? Here is the code:

    	private static void \_ctrlParent\_DragOver(object sender, DragEventArgs e) 
    	{
    		try
    		{
    			if (DragDropHandler.CanDropHere((Control)sender, e.Data))
    			{
    				// Control dragged to
    				Control cthis = (Control)sender;
    				// Control dragged
    				CardControl ctrl = (CardControl)DragDropHandler.GetControl(e.Data, true, true);
    				e.Effect = DragDropEffects.Move;				
    
    				if (!(ctrl is IDragDropEnabled))
    				{
    					return;
    				}
    				if (cthis.Name != ctrl.Name)
    				{
    					if ((ctrl.HasChildren == false) && (ctrl.blnCardFaceStatus==true) 
    						|| ((ctrl.HasChildren == true) && (ctrl.blnCardFaceStatus=true)))
    					{
    						//MessageBox.Show("cthis is " + cthis.Name + " and ctrl is " + ctrl.Name);
    						ctrl.Parent.Controls.Remove(ctrl);
    						ctrl.Parent = cthis;   // Here is where the circular reference occurs.
    						cthis.Controls.Add(ctrl);
    						ctrl.BringToFront();
    					}
    					else if ((ctrl.HasChildren == true) && (ctrl.blnCardFaceStatus==false)
    						|| ((ctrl.HasChildren == false) && (ctrl.blnCardFaceStatus=false)))
    					{
    						return;
    					}
    				}
    				else
    				{
    					return;
    				}
    				Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y));
    				ctrl.Left = NewLocation.X - dragPoint.X;
    				ctrl.Top = NewLocation.Y - dragPoint.Y;
    			}
    			else
    			{
    				e.Effect = DragDropEffects.None;
    			}
    		}
    		catch (System.ArgumentException)
    		{
    			MessageBox.Show("Argument Exception Error");
    		}
    	}
    

    modified on Monday, December 24, 2007 8:12:20 PM

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups