本文介绍了我可以为e.Data.GetDataPresent写一个Select..Case语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个将DataGridView中的项目拖放到TreeView上的应用程序。


现在我必须使用If..Then..Else语句。

如果e.Data.GetDataPresent(" System.Windows.Forms.DataGridViewRow",True)则
e.Effect = DragDropEffects .Copy
退出Sub
结束如果
'查看是否有拖动的TreeNode
如果e.Data.GetDataPresent(" System.Windows.Forms.TreeNode",True) )然后
'TreeNode发现允许移动效果
e.Effect = DragDropEffects.Move
否则
'没有找到TreeNode,阻止移动
e.Effect = DragDropEffects.None
结束如果

如果可以这样做的话会更加整洁:

 Select Case e.GetDataPresent()
Case" System.Windows.Forms.DataGridView",True
e.Effect = DragDropEffects.Move
Case" System.Windows.Forms.TreeView",True
e.Effect = DragDropEffects.Move
Case Else
e.Effect = DragDropEffects.None
结束选择

我不知道这是否可行。


谢谢,






MRM256

解决方案


I am writing an application that drags and drops items from a DataGridView onto a TreeView.

Right now I have to use If..Then..Else statements for this.

If e.Data.GetDataPresent("System.Windows.Forms.DataGridViewRow", True) Then
            e.Effect = DragDropEffects.Copy
            Exit Sub
        End If
        'See if there is a TreeNode being dragged
        If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) Then
            'TreeNode found allow move effect
            e.Effect = DragDropEffects.Move
        Else
            'No TreeNode found, prevent move
            e.Effect = DragDropEffects.None
        End If

It would be much neater if it could be done like:

  Select Case e.GetDataPresent()
            Case "System.Windows.Forms.DataGridView", True
                e.Effect = DragDropEffects.Move
            Case "System.Windows.Forms.TreeView", True
                e.Effect = DragDropEffects.Move
            Case Else
                e.Effect = DragDropEffects.None
        End Select

I don't know if this is possible.

Thanks,


MRM256

解决方案


这篇关于我可以为e.Data.GetDataPresent写一个Select..Case语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 09:07