I am building a program where for part of it the user can enter a parameter which will then query a database and populate a DataTable with the results if the number of results is greater than 1 it will call a "lookup" form to popuate a DataGridView with the DataTable, from this the user can select a row and the result is passed back to the main form or if the result is not there the "lookup" can be closed.
This works fine the first time the parameter is used to query and opens the "lookup" form and populates the DGV, but if the user returns the the main program after using the lookup form and enters a new parameter and the lookup form opens again the DataGridView is not created and populated. But i am 99% sure the DateTable is being populated as if the row count is 1 it will automatically return the single value and this is happening even after the lookup form has been used.
So it is just when the Lookup form is being used a second time the DataGridView is not being popuated or the DataTable is not being passed.
Any help would be very grateful as i have being trying differnt things all day. Please find below snippets of my code which basically shows the opening of the Lookup form and how i am passing the DataTable, and how the Lookup Form uses the DataTable. I have also attached 2 screenshots showing the Lookup form the first time its used and then when it is recalled.
'This performs the query on the database and populates the DataTable if the results (if any)
Call DescSearch()
'Checks if the Search has produced more than 1 row of result
If DTDesc.Rows.Count > 1 Then
'If so open the Lookup form to show results
Dim frmDescSearch As New frmDescSearch
'Pass the DataTable to the Lookup Form and show the form
frmDescSearch.DTDesc = Me.DTDesc
frmDescSearch.ShowDialog()
ElseIf DTDesc.Rows.Count = 1 Then
'If the Search has produced only one result apply this to the text box
txtDesc.Text = LTrim(DTDesc.Rows(0)("Description").ToString)
End If
'Clear the DataTable ready for next search if required
DTDesc.Clear()
This is the code for lookup form, when it opens is creates the DataSet attaches the DataTable to the DataGridView and sets a couple parameters within the DGV.
Public Class frmDescSearch
Public DTDesc As DataTable
Public DSDesc As DataSet
Private Sub frmDescSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call InitializeTable()
If dgvDesc.Rows.Count > 0 Then
dgvDesc.Rows(0).Selected = False
End If
End Sub
Private Sub InitializeTable()
DSDesc = New DataSet()
DSDesc.Tables.Add(DTDesc)
dgvDesc.DataSource = DSDesc
dgvDesc.DataMember = "Search"
dgvDesc.Columns("Description").ReadOnly = True
Dim xCol As New DataGridViewColumn
'Dim xRow As New DataGridViewRow
xCol = dgvDesc.Columns(0)
xCol.Width = 200
dgvDesc.Font = New Font("Arial", 9)
End Sub
End Class
When i get the Lookup form working correctly, this form will either return the selected result or the form will be closed back to the Main form.
Again thanks in advance for any help. I will be more than happy to answer any questions regarding other code i haven't included which may be causing this but at the minute i don't understand why this is happening.

New Topic/Question
Reply




MultiQuote



|