Jul*_*lin 7 c# drag-and-drop exception winforms
我有一个WinForms应用程序,我正在两个TreeViews之间拖放.
在某些时候,我想拒绝底层业务实现中的操作,所以我抛出一个Exception.我可以在"输出"窗口中看到"异常",但问题是我无法在UI中看到它并且它不会崩溃.
例外在哪里?
以下是一些描述问题的代码:
private TreeView tvLeft;
private TreeView tvRight;
private Dictionary<string, int> dico = new Dictionary<string, int>();
void tvLeft_DragDrop(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(typeof(TreeNode))) {
var tnSource = (TreeNode) e.Data.GetData(typeof(TreeNode));
var tnDestination = tvLeft.GetNodeAt(tvLeft.PointToClient(new Point(e.X, e.Y)));
// if I drag-drop the same node twice, there sould be an Exception
// since the key is already in the dictionary...
// ...but I get no Exception in the UI, the Application.ThreadException
// or Appomain.CurrentDomain.UnhandledException handlers
dico.Add(tnSource.Name, (new Random()).Next());
}
}
Run Code Online (Sandbox Code Playgroud)