Results 1 to 1 of 1

Thread: [2005] How to Click and Select a row for processing in DataGridview control

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    134

    Question [2005] How to Click and Select a row for processing in DataGridview control

    I have a couple of methods define to help User click to select a row of my datagridview . Problem is when I click a row in my grid, nothing happens, none of the events are fired when I only use one. However when I have all three events in my code, As soon as the page loads, one of the three fires even before user is able to click anything and runs into an error. Does anyone know the best way to handle this issue please??



    Code:
        Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
            If LOADING = True Then
                'do nothing else 
                LOADING = False
                Return
            Else
                ' Show the customer order screen when the user presses Enter except for
                ' where the Customer ID is not yet known (such as the New Row).
                Me.ProductionID = CInt(DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("PRODUCTIONID").Value)
                Dim tca As Integer = CInt(DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("TCAPO").Value)
                Dim WPO As String = DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("WPO").Value
                'get the packedID associated with this from Packed Table 
                getPackedID(tca, WPO)
    
                If CBool(Not Me.ProductionID) Then
                    ' Stop the DataGridView from processing the enter.
                    Dim co As ProductionData = New ProductionData
                    co.ProductionID = Me.ProductionID
                    co.packedID = Me.PACKEDID
                    co.ShowDialog(Me)
    
                End If
            End If
        End Sub
    
    
        Private Sub DataGridView1_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
    
            ' Show the customer order screen when the user presses Enter except for
            ' where the Customer ID is not yet known (such as the New Row).
            If LOADING = True Then
                'do nothing else 
                LOADING = False
                Return
            Else
                If e.KeyData = Keys.Enter Then
    
                    Me.ProductionID = CInt(DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("ProductionID").Value)
                    Dim tca As Integer = CInt(DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("TCAPO").Value)
                    Dim WPO As String = DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("WPO").Value
                    'get the packedID associated with this from Packed Table 
                    getPackedID(tca, WPO)
    
                    If CBool(Not Me.ProductionID) Then
                        ' Stop the DataGridView from processing the enter.
                        e.Handled = True
                        Dim co As ProductionData = New ProductionData
                        co.ProductionID = Me.ProductionID
                        co.packedID = Me.PACKEDID
                        co.ShowDialog(Me)
    
                    End If
                End If
            End If
            LOADING = True
        End Sub
    
        ' Detecting Which Cell Is Clicked
        '---when the user clicks on the datagridview control---
        Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
            If LOADING = True Then
                'do nothing else 
                LOADING = False
                Return
            Else
    
                '---prints the content of the cell---
                Dim x As Integer = e.RowIndex
                '    'get the ProductionID for this row 
                Me.ProductionID = CInt(DataGridView1.Rows(e.RowIndex).Cells("ProductionID").Value)
                'get the packedID associated with this from Packed Table 
                Dim tca As Integer = CInt(DataGridView1.Rows(e.RowIndex).Cells("TCAPO").Value)
                Dim WPO As String = DataGridView1.Rows(e.RowIndex).Cells("WPO").Value
                getPackedID(tca, WPO)
    
                Dim co As ProductionData = New ProductionData
                co.ProductionID = Me.ProductionID
                co.packedID = Me.PACKEDID
                co.ShowDialog(Me)
    
            End If
        End Sub
    
        Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
            Me.ProductionID = CInt(DataGridView1.Rows(DataGridView1.CurrentCellAddress.Y).Cells("ProductionID").Value)
            If LOADING = True Then
                'do nothing else 
                LOADING = False
                Return
            Else
                If CBool(Not Me.ProductionID) Then
                    ' Stop the DataGridView from processing the enter.
                    ' Stop the DataGridView from processing the enter.
                    Dim co As ProductionData = New ProductionData
                    co.ProductionID = Me.ProductionID
                    co.packedID = Me.PACKEDID
                    co.ShowDialog(Me)
                    Me.Close()
                End If
            End If
        End Sub
    thanks in advance

    Reaction
    Last edited by Reaction; May 9th, 2007 at 04:43 AM. Reason: Retouch the Type

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