如何在VB.NET中忽略MouseClick事件 [英] How to ignore MouseClick Event in VB.NET
问题描述
嗨朋友们,
我项目中的datagridview中有DataGridViewCheckBoxColumn单元格。
我想要用户可以在满足条件时单击它来检查DataGridViewCheckBoxColumn。
当条件不满足时,我希望DataGridViewCheckBoxColumn忽略MouseClick_event。 />
我不知道我必须在MouseClick_event处理程序中放置代码来实现这个目标。
任何帮助非常感谢。
提前致谢
从下面的评论中复制的其他信息
我以为会有类似于Key.Press_Event中的e.Handled。
为了清楚起见,我已经包含了我的代码
Hi friends,
I have DataGridViewCheckBoxColumn cell in datagridview in my project.
I want the user to be able check DataGridViewCheckBoxColumn by clicking it when certain a condition is met.
When the condition is not met I expect the DataGridViewCheckBoxColumn to ignore the MouseClick_event.
I do not know the code I must place in the MouseClick_event handler to achieve this objective.
Any assistance would greatly appreciated.
Thanks in advance
Additional information copied from comment below
I thought there will be something like e.Handled as in KeyPress_Event.
For the purpose of clarity I have included my code
If DataGridView1.CurrentCell.ColumnIndex = 9 Then
'EventArgs.Empty = True
Select Case e.Button
Case (Windows.Forms.MouseButtons.Left) Or (Windows.Forms.MouseButtons.None) Or (Windows.Forms.MouseButtons.Middle)
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
'EventArgs = Empty
Case Windows.Forms.MouseButtons.Middle
Case Windows.Forms.MouseButtons.Right
Case Else
End Select
End If
推荐答案
对于你所描述的,最简单的方法是
For what you describe, the easiest way would be
if condition != TRUE
return
//here the rest of the code out of the if
$ / b $ b或
or
if condition == TRUE
{
//your code here
}
else
return
如果这不符合您的要求要做...请使用改进问题小部件并更详细地解释
OP的最后一条评论,其中为其他人添加了自制的解决方法
非常感谢。我找到了解决问题的方法。我只是在不满足条件时执行代码(消息框并使单元格成为只读)。完整例程如下所示:
If that doesn't fit what you want to do... please use the "improve question" widget and explain it more detailed
OP's last comment with self-made workaround added here for other people
Thanks so much. I have found a handle to my problem. I just put the code(messagebox and making the cell readonly)to execute when the condition is not met. Complete routine is shown below:
Private Sub DataGridView1_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
If (DataGridView1.CurrentCell.ColumnIndex = 12) Then
If (DataGridView1.CurrentRow.Cells("TransType").FormattedValue.ToString.ToUpper <> "E") AndAlso (DataGridView1.CurrentRow.Cells("TransType").FormattedValue.ToString.ToUpper <> "D") Then
'EventArgs.Empty = True
Select Case e.Button
Case Windows.Forms.MouseButtons.Left
DataGridView1.CurrentCell.ReadOnly = True
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
'EventArgs = Empty
Case Windows.Forms.MouseButtons.Middle
DataGridView1.CurrentCell.ReadOnly = True
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
'EventArgs = Empty
Case Windows.Forms.MouseButtons.Right
DataGridView1.CurrentCell.ReadOnly = True
MessageBox.Show("Editing this column is not allowed for this transaction", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
'EventArgs = Empty
Case Else
DataGridView1.CurrentCell.ReadOnly = False
End Select
Else
DataGridView1.CurrentCell.ReadOnly = False
End If
End If
End Sub
非常感谢非常适合您的帮助
Thanks so much for your assistance
这篇关于如何在VB.NET中忽略MouseClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!