System.ArgumentException Assistance Needed... [modified]
C#
1
Posts
1
Posters
0
Views
1
Watching
-
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