Results 1 to 7 of 7

Thread: [RESOLVED] Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Resolved [RESOLVED] Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    I have various routines that are executed when you click in a particular cell, how do i prevent the routines from executing when i click on the select row button on the far left of the DGV?



    regards
    toe

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    All the cell-related events of the DataGridView provide a ColumnIndex and a RowIndex. You test the ColumnIndex and don't do anything unless its the index of a column for which you want to do some processing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    Are you using CellContentClick or Mouse Events? the arguments are a bit different on either one
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    DataGridView.CellEnter

    since you mentioned it i did try "DataGridView.MouseEnter" but pretty much the same result


    Code:
       Private Sub PaymentsDataGridView_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PaymentsDataGridView.MouseEnter
    
            If PaymentsDataGridView.CurrentRow.Cells(2).Selected Then
                paymentsDescriptions.Show()
            End If
       End Sub

  5. #5
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    Odd, cellEnter should not be triggered when you select the row headers.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  6. #6

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    This seems to be the event to use

    Code:
    Private Sub PaymentsDataGridView_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles PaymentsDataGridView.CellContentClick

    *EDIT
    incorrect as will not fire cell events when there is no content in the cell
    Last edited by toecutter; Oct 26th, 2013 at 06:40 PM.

  7. #7

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Prevent DataGridView Select Row From Executing Cell Mouse Click Routines

    got it with this


    Code:
          If PaymentsDataGridView.CurrentCell.ColumnIndex = (2) Then
                    Dim intCurrentCol2 As Integer = Nothing
                    Dim intCurrentRow2 As Integer = Nothing
                    intCurrentCol2 = PaymentsDataGridView.CurrentCell.ColumnIndex
                    intCurrentRow2 = PaymentsDataGridView.CurrentCell.RowIndex
                    PaymentsDataGridView.Rows(intCurrentRow2).Cells(intCurrentCol2).Selected = True
                    paymentsDescriptions.Show()
                End If

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