Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Cancel/Clear Event Queue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 15 Oct 2007 12:56 GMT
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?
rowe_newsgroups - 15 Oct 2007 13:10 GMT
> In VB6 I have a screen the has a text box and a datagrid
>
[quoted text clipped - 9 lines]
>
> How do I do that?

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

Thanks,

Seth Rowe
Steve - 15 Oct 2007 14:36 GMT
> > In VB6 I have a screen the has a text box and a datagrid
>
[quoted text clipped - 15 lines]
>
> Seth Rowe

Seth,

I already do that, but the mousedown for the datagrid (not the
textbox) still executes.
rowe_newsgroups - 15 Oct 2007 15:08 GMT
> > > In VB6 I have a screen the has a text box and a datagrid
>
[quoted text clipped - 20 lines]
> 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
Steve - 15 Oct 2007 15:44 GMT
> > > > In VB6 I have a screen the has a text box and a datagrid
>
[quoted text clipped - 37 lines]
>
> - 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
rowe_newsgroups - 15 Oct 2007 16:23 GMT
> > > > > In VB6 I have a screen the has a text box and a datagrid
>
[quoted text clipped - 47 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.