Cancel/Clear Event Queue

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

In VB6 I have a screen the has a text box and a datagrid

If I click the datagrid, the 1st event is to validate the textbox and
then the 2nd event is a datagrid mousedown event. If a get an error
message in the textbox validate it seems the mousedown event is never
executed.

In VB.Net it executes the textbox validation and then displays the
error, but still executes the mousedown event. It appears that I have
to explicitly cancel/clear the event queue in VB.Net if there is an
error.

How do I do that?
 
In VB6 I have a screen the has a text box and a datagrid

If I click the datagrid, the 1st event is to validate the textbox and
then the 2nd event is a datagrid mousedown event. If a get an error
message in the textbox validate it seems the mousedown event is never
executed.

In VB.Net it executes the textbox validation and then displays the
error, but still executes the mousedown event. It appears that I have
to explicitly cancel/clear the event queue in VB.Net if there is an
error.

How do I do that?

Did you use e.Cancel = True in the Validating event handler?

Thanks,

Seth Rowe
 
Did you use e.Cancel = True in the Validating event handler?

Thanks,

Seth Rowe


Seth,

I already do that, but the mousedown for the datagrid (not the
textbox) still executes.
 
Seth,

I already do that, but the mousedown for the datagrid (not the
textbox) still executes.

Alright, I figured I'd have you check the basics before I spent too
much time looking into it (lazy me :-)).

Imo, the MouseDown event should fire, because after all you did press
the mouse down on the datagrid. The behavior of a failed validation is
by default to just prevent a focus change, and not to prevent any
other control from performing an action. If you need to run some code
conditionally based on whether or not the textbox's validation
succeeded, the easiest (imo) method would be to use a simple boolean
flag that is checked by the MouseDown event handler.

Thanks,

Seth Rowe
 
Alright, I figured I'd have you check the basics before I spent too
much time looking into it (lazy me :-)).

Imo, the MouseDown event should fire, because after all you did press
the mouse down on the datagrid. The behavior of a failed validation is
by default to just prevent a focus change, and not to prevent any
other control from performing an action. If you need to run some code
conditionally based on whether or not the textbox's validation
succeeded, the easiest (imo) method would be to use a simple boolean
flag that is checked by the MouseDown event handler.

Thanks,

Seth Rowe- Hide quoted text -

- Show quoted text -

Seth,

I agree. Although, this code will be used in over 100 projects, and I
hate to drag around an extra variable for each. Can you think of
anything that would be a little more imaginative?


Thanks ,

Steve
 
Seth,

I agree. Although, this code will be used in over 100 projects, and I
hate to drag around an extra variable for each. Can you think of
anything that would be a little more imaginative?

Thanks ,

Steve

Well, you could use Add/Remove Handler to dynamically control whether
the mousedown event is processed by your event handler.

Something like:

///////////////
Public Class Form1

Private Sub TextBox1_Validating(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
TextBox1.Validating
e.Cancel = String.IsNullOrEmpty(TextBox1.Text)

If e.Cancel Then RemoveHandler DataGridView1.MouseDown,
AddressOf DataGridView1_MouseDown
End Sub

Private Sub TextBox1_Validated(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.Validated
AddHandler DataGridView1.MouseDown, AddressOf
DataGridView1_MouseDown
End Sub

Private Sub DataGridView1_MouseDown(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles
DataGridView1.MouseDown
MessageBox.Show("MouseDown")
End Sub

End Class
///////////////

Thanks,

Seth Rowe
 
Back
Top