Data Grid View and a Binding Navigator, The DGV Does Not respond after I Click a Button.

Gary Simpson 471 Reputation points
2023-04-21T09:48:56.2866667+00:00

Hello Again Good People. I have a Data Grid View Called (DGVPaymentsOut) and 5 Buttons Called CmdFirst, CmdPrevious, CmdNext, CmdLast, CmdClear When my form loads the (DGVPaymentsOut) is populated with the data in my SQL Database. When I click any one of the buttons Lets say "CmdNext" Then the next Row in my DGV is highlighted everything is working Fine. But if I initiate a search from a textbox called (TxtFilter) The DGV shows only the Records/rows with what is inserted into the textbox. Now here is where I have the issue None of the Buttons work except the CmdClear which Re-Populates all of the records. But the rest of the buttons do not work for the Data Grid View If I click Any of the Buttons (CmdNext, CmdLast, CmdPrevious, or CmdFirst). the Data Grid View stays on the first row only and does not move. But When I close and reload the form all the buttons work as intended until I do a search from the textbox. I Hope any of you Good People Can Tell me what is missing or what I have done Wrong Kind Regards Gary The Code I have at the moment>>>


Private Sub CmdFirst_Click(sender As Object, e As EventArgs) Handles CmdFirst.Click

        PaymentsOutBindingNavigator.MoveFirstItem.PerformClick()
        Label14.Text = PaymentsOutBindingNavigator.PositionItem.Text
        Label15.Text = PaymentsOutBindingNavigator.CountItem.Text
        ColourChange()
    End Sub

    Private Sub CmdPrevious_Click(sender As Object, e As EventArgs) Handles CmdPrevious.Click

        PaymentsOutBindingNavigator.MovePreviousItem.PerformClick()
        Label14.Text = PaymentsOutBindingNavigator.PositionItem.Text
        Label15.Text = PaymentsOutBindingNavigator.CountItem.Text
        ColourChange()
    End Sub

    Private Sub CmdNext_Click(sender As Object, e As EventArgs) Handles CmdNext.Click

        PaymentsOutBindingNavigator.MoveNextItem.PerformClick()
        Label14.Text = PaymentsOutBindingNavigator.PositionItem.Text
        Label15.Text = PaymentsOutBindingNavigator.CountItem.Text
        ColourChange()
    End Sub

    Private Sub CmdLast_Click(sender As Object, e As EventArgs) Handles CmdLast.Click

        PaymentsOutBindingNavigator.MoveLastItem.PerformClick()
        Label14.Text = PaymentsOutBindingNavigator.PositionItem.Text
        Label15.Text = PaymentsOutBindingNavigator.CountItem.Text
        ColourChange()
    End Sub


 Public Sub LoadGrid(Optional Query As String = "")

        If Query = "" Then
            SQL.ExecQuery("SELECT * FROM PaymentsOut;")

        Else
            SQL.RunQuery(Query)

        End If

        'Error Handling
        If SQL.HasException(True) Then Exit Sub

        'Load DGV ( DGVPaymentsOut )
        DGVPaymentsOut.DataSource = SQL.SQLDT

    End Sub


    Private Sub FindCompany()

        SQL.AddParam("@Item", "%" & TxtFilter.Text & "%")
        'Load The DataGridView ( DGVPaymentsOut ) Where Company Name = TxtFilter/Company Name
        LoadGrid("SELECT * FROM PaymentsOut WHERE Company LIKE @Item;")

    End Sub

    Private Sub TxtFilter_TextChanged(sender As Object, e As EventArgs) Handles   TxtFilter.TextChanged
        FindCompany()

    End Sub
.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,059 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,768 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Gary Simpson 471 Reputation points
    2023-05-01T10:21:53.8933333+00:00

    I have Changed the Event from Row Enter to Cell Click event in my Data Grid View.

    And add the code after research.

    I have removed the Buttons that was bound to the Binding Navigator And I now use Data Grid View Cell Click Event.

    Code Below...

    
    Private Sub DGVMultiRecords_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGVMultiRecords.CellClick
    
            Dim Index As Integer
            Index = e.RowIndex
            Dim SelectedRow As DataGridViewRow
    
            SelectedRow = DGVMultiRecords.Rows(Index)
            LbMultiDropID.Text = SelectedRow.Cells(0).Value.ToString()
    
        End Sub
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.