Event when DataGridView row is clicked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    Event when DataGridView row is clicked

    Hi,

    I need an event to fire off when someone clicks anyplace within a
    DataGridView row, but whether I use CellContentClic k or CellClick, the
    event only fires off when clicking on the text within the row and not
    anyplace within the row. Is there someway for the event to fire off
    regardless of where they click in the row?

    Here's a snippet:
    Private Sub dgvStuff_CellCo ntentClick(ByVa l sender As
    System.Object, ByVal e As
    System.Windows. Forms.DataGridV iewCellEventArg s) Handles
    dgvStuff.CellCo ntentClick
    '' blah blah blah my code goes here
    End Sub

    Thanks --

    Alex
  • Kevin S Gallagher

    #2
    Re: Event when DataGridView row is clicked

    I don't know if this fits your needs fully but worth trying


    Private clickedCell As DataGridViewCel l
    ....
    Private Sub GridView_MouseD own(ByVal sender As Object, ByVal e As
    MouseEventArgs) Handles GridView.MouseD own
    Dim hit As DataGridView.Hi tTestInfo = DataGridView1.H itTest(e.X,
    e.Y)
    If hit.Type = DataGridViewHit TestType.Cell Then
    clickedCell =
    DataGridView1.R ows(hit.RowInde x).Cells(hit.Co lumnIndex)
    Dim CurrentCell As DataGridViewCel l =
    GridView.Item(h it.ColumnIndex, hit.RowIndex)
    End If
    End Sub

    "Alex" <samalex@gmail. comwrote in message
    news:4034e917-5057-4a0a-a8ef-036afc62e4f0@p1 0g2000prf.googl egroups.com...
    Hi,
    >
    I need an event to fire off when someone clicks anyplace within a
    DataGridView row, but whether I use CellContentClic k or CellClick, the
    event only fires off when clicking on the text within the row and not
    anyplace within the row. Is there someway for the event to fire off
    regardless of where they click in the row?
    >
    Here's a snippet:
    Private Sub dgvStuff_CellCo ntentClick(ByVa l sender As
    System.Object, ByVal e As
    System.Windows. Forms.DataGridV iewCellEventArg s) Handles
    dgvStuff.CellCo ntentClick
    '' blah blah blah my code goes here
    End Sub
    >
    Thanks --
    >
    Alex

    Comment

    Working...