我可以为e.Data.GetDataPresent写一个Select..Case语句吗? [英] Can I write a Select..Case Statement for e.Data.GetDataPresent?
问题描述
我正在编写一个将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
我会伸出脖子说不。您正试图在案件中做出决定。当你在一步中显示时,我不知道如何做到这一点。
我也会伸出脖子,说你的衣服没什么问题。
:)
PS也许这个?
如果e.Data.GetDataPresent(" System.Windows.Forms.DataGridViewRow",True)然后
e.Effect = DragDropEffects.Copy
Else
'查看是否有拖动的TreeNode
如果e.Data.GetDataPresent(" System.Windows.Forms.TreeNode",True)那么
'找到TreeNode允许移动效果
e.Effect = DragDropEffects.Move
Else
'找不到TreeNode,阻止移动
e.Effect = DragDropEffects.None
结束如果
结束如果
PS有一个在可能的情况下删除出口sub的原因。这样,只有一种方法可以脱离例程,对编译器来说效率更高。然而,在大多数情况下,你永远不会注意到差异。然而,如果你有额外的代码,最后应该执行
,那么你就不能轻易退出sub。
不是有两种方法,他们称之为拳击吗? / p>
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
I will stick my neck out and say no. You are attempting to make a decision in the case. I dont know of a way to do that as you show in a single step.
I will also stick my neck out and say there is nothing wrong with what you have.
:)
PS Maybe this?
If e.Data.GetDataPresent("System.Windows.Forms.DataGridViewRow", True) Then e.Effect = DragDropEffects.Copy Else '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 End If
PS There is a reason to remove the exit sub when possible. That way there is only one way out of the routine and more efficient for the compiler. However it most cases you will never notice the diff. And however if you have additional code that should be executed at the end then you cant exit sub easily etc.Isnt having the two ways out what they call Boxing?
这篇关于我可以为e.Data.GetDataPresent写一个Select..Case语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!