CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2001
    Posts
    6

    Datagrid Double-click event

    I have a datagrid with records from Database. When the user double-clicks on a record, the code will open that record. My problem is that if the user double-clciks on the column header, I will get the event and the current selected record will be opened. I don't want this to happen since I use HeadClick to sort the column. If the user clicks on the column header too fast, it will be treated as double-click and opens the current selected record. I want to open the record only when the user clicks on the data rows, not the header. Is there any way to achieve this? Thanks.

    Dion


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Datagrid Double-click event

    on double click event check if row =0
    if Grid1.row = 0 then
    'do something
    else
    'do something
    end if

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Feb 2001
    Posts
    6

    Re: Datagrid Double-click event

    Thanks for your reply. However, if I double -click on the first row, it also has datagrid1.row = 0. Therefore datagrid1.row = 0 does not necessary mean that click is on the column header. Any suggestions? Thanks very much.


  4. #4
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Datagrid Double-click event

    I have used this on a MSFlex Grid to reset the "Right" clicked cell for a popup menu. It should give you the right Cell number and with a little modification you can check for Row Zero.



    private Sub Grd1_MouseUp(Button as Integer, Shift as Integer, X as Single, Y as Single)
    Dim I as Long
    Dim J as Long
    Dim K as Long
    Dim Off as Long

    If Button = 2 then
    K = 0
    Off = 0
    If Grd1.LeftCol <> 1 then
    for I = 1 to Grd1.LeftCol - 1
    Off = Off + Grd1.ColWidth(I)
    next I
    End If
    K = Off * -1
    for I = 0 to 15
    K = K + Grd1.ColWidth(I)
    If X < K then
    K = 0
    Off = 0
    If Grd1.TopRow <> 1 then
    for J = 1 to Grd1.TopRow - 1
    Off = Off + Grd1.RowHeight(J)
    next J
    End If
    K = Off * -1
    for J = 0 to Grd1.rows - 1
    K = K + Grd1.RowHeight(J)
    If Y < K then
    Exit for
    End If
    next J
    Exit for
    End If
    next I
    Grd1.Row = J
    Grd1.Col = I
    PopupMenu frmStart.mnuPopup13
    End If

    End Sub





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured