?
Solved

DataGrid Double-Click Event Causing Problems By Selecting Cells While Event is Executing

Posted on 2009-04-13
3
Medium Priority
?
475 Views
Last Modified: 2012-06-27
Dear Experts,

I have an odd problem which I'm not sure how to fix. I have an event wired to the datagrid, on the double click, so something like..
Private Sub mydatagrid_CellDoubleMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles mydatagrid.CellMouseDoubleClick

What the code in the event does is figure out which cell they clicked on, and take the value and then look up that record on a website. The whole time it is looking up the record (due to the delay of web this could take 5 seconds) any movement of the mouse causes multiple cells to hilite along wherever the mouse goes.

So I've been trying to think of ways to stop this behaviour, and it seems like I have to find a way to let the double click event end, like immediatly, and then run my code to open the web pages.

I tried to do this with something like:
        RaiseEvent EP_myDataGrid_DblClick(sender, e)
        ClearAllOtherSelected(sender, e)   'I have posted the code for ClearAllOtherSelected Below

..but what I discovered is that simply raising an event from an event doesn't cause the first event to finish, but rather everything is asyncronous. I'm not sure then what I should do, but does anyone have any ideas? I'm hesitant to set up all the web code on a different thread, because there are so many functions and subs involved, I'm not sure how I'd like to handle it, plus if they double click any other record while the other thread is running, and I try to start yet another instance, which would mean another instance of my web form (which is a form hosting a webbrowser), what will it do? I kinda really only want it to be looking up one at any given time.

Any ideas? Thanks! ~Michael


Private Sub mydatagrid_CellDoubleMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles mydatagrid.CellMouseDoubleClick
        RaiseEvent EP_myDataGrid_DblClick(sender, e)
        ClearAllOtherSelected(sender, e)
    End Sub
 
    Private Sub EventProc_myDataGrid_DblClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Me.EP_myDataGrid_DblClick
        My.Application.DoEvents()
        Dim colName$, parcelNum$, county$
        If e.ColumnIndex = -1 And e.RowIndex > -1 Then
            'This occurs when they double-click on the absolute left-most column (Not data)
            'we can open the single record view form
            SingleRecView.flagCameFromDGDblClick = True
            btnSRV_Click(sender, New System.EventArgs)
            Exit Sub
        ElseIf e.RowIndex < 0 Or e.ColumnIndex < 0 Then
            'This occurs any time when they double-click somewhere that isn't data
            Exit Sub
        End If
 
        'Otherwise If it's a Parcel, Send it off to the Web
        colName = Me.mydatagrid.Columns(e.ColumnIndex).Name
        If colName.ToUpper() = "PARCEL" Then
            parcelNum = nz(Me.mydatagrid.Rows(e.RowIndex).Cells("Parcel").Value)
            county = UCase(nz(Me.mydatagrid.Rows(e.RowIndex).Cells("County").Value))
            '
            If parcelNum <> "" And county <> "" Then
                'ClearAllOtherSelected(sender, e)
                EnterWebEntry(parcelNum, county)
                'ClearAllOtherSelected(sender, e)
                'My.Application.DoEvents()
            End If
        End If
    End Sub
 
    Private Sub ClearAllOtherSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        'Line should prevent cells from all hiliting while web is loading
        Try
            Me.mydatagrid.ClearSelection()
            Me.mydatagrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Selected = True
        Catch ex As Exception
            'this happens when they switch to the singlerecview while the webpage is loading
        End Try
    End Sub

Open in new window

0
Comment
Question by:JeffreyDurham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24133610
Can you show the code that causes multiple cells to be highlighted when you doubleclick a cell. If the code in the event handler blocks the UI thread I can't see how any issues occur.
0
 
LVL 5

Accepted Solution

by:
srinivasbn earned 2000 total points
ID: 24134417
Hi JeffreyDurham,

why don't you put the datagrid.enabled=false until the end of the process instead of canceling the previous events. I feel it is too better. When it is in disabled mode the user can't hit the datagrid.

Srinivas.B.N
0
 

Author Comment

by:JeffreyDurham
ID: 24210641
oobayly:

there is no code that hilites cells, it's unmanaged, just part of the datagrid functionality. I have code that tries to unhilite the grid, but it doesn't work. I think the actual hiliting of the datagrid is occuring when the program waits for the web page to load, because it uses my.application.doevents in a loop until the web pages finishes. I suppose I could have the program appear to freeze and not use my.application.doevents or something but I really don't want it to appear frozen to our users. Really, I just wish I could let the event finish, and then after it's totally done, call up my web page, but I don't know how to do that without linking events to one another and this seems to result in the first staying in action until the second finishes.

srinivasbn:
actually, this is not a bad idea, and I tried it and it's the first thing I've tried that does work. If no one can come up with any other way to do what I originally intended I will take this as acceptable and give you the points.

Thanks for your help guys! ~Michael
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question