Results 1 to 10 of 10

Thread: Reuse of DGV doesn't fill the grid

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Posts
    9

    Question Reuse of DGV doesn't fill the grid

    I have an invoice form using a data grid (DGVInvoice). When I start to enter a description, this shows another grid in the same Form (DGVMatches) that shows all matches from the Invoice/Description field in the database. Clicking any of the matches updates the DGVInvoice description field.

    This works perfectly on Line 1 of the invoice, but when I enter a description on subsequent lines, no matches are displayed in DGVMatches (although the DGVMatches header shows the search term correctly).

    Code in DGVInvoice to call DGVMatches:

    Code:
    Private Sub ShowMatches()
    
          ' @@ Fetch Descriptions from LineEntry table
          Dim pSQL As String = "SELECT DISTINCT [Desc] FROM LineEntry WHERE [Desc] LIKE '" & mCellContent & "%' ORDER BY [Desc] "
          Dim m_Datatable As New DataTable
    
          Using cnn As New OleDbConnection(gs_Connection)
              cnn.Open()
              Using dad As New OleDbDataAdapter(pSQL, cnn)
                  dad.Fill(m_Datatable)
                  dad.Dispose()
              End Using
              cnn.Close()
          End Using
    
          GbMatching.Text = "Matching entries for '" & mCellContent & "'"
    
          If m_Datatable.Rows.Count = 0 Then  ' ** No data
              GbMatching.Visible = False
          Else
              With DgvMatches
                  .DataSource = m_Datatable
                  GbMatching.Visible = True
                  .Columns(0).Width = 360
                  .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft   ' @@ Aligns cells
                  .Refresh()
              End With
              m_Datatable = Nothing
          End If
    
        End Sub
    Code in DGVMatches to fill the DGVInvoice Description field:

    Code:
    Private Sub DgvMatches_Click(sender As Object, e As EventArgs) Handles DgvMatches.Click
          With DgvInvoice
              .CurrentCell.Value = DgvMatches.CurrentCell.Value         
              DgvInvoice.BeginEdit(False)
          End With
    
          GbMatching.Visible = False
          mMatchFound = True
          DgvMatches.Dispose()
    
      End Sub
    Can anyone help with this?
    Last edited by jmcilhinney; Jul 9th, 2024 at 12:04 AM.

Tags for this Thread

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