S
Steve A.
Here is the scenario:
I have a project that uses two forms. Form1 uses a SQL
Connection, several DataAdapters for various tables,
DataSet, and a DataView that I filter by user-selected
field names and associated criteria. Form2 has a couple
of read-only text fields to show the user the search
field and criteria they entered plus a DataGrid that is
populated from the DataView. There is a Public Class
defined to hold shared variables.
Code:
Public Class SharedVariables
Public Shared SelectedKey As String ' Make it shared
End Class
Code:
' Define an instance of the search form
Dim Form2 As New frmSearchResults
' Set the txtSearchingFor textbox and field name
to data from the calling form
Form2.txtSearchingFor.Text = txtSearch.Text
..
..
..
If cboSearch.SelectedIndex = 5 Then
myField = "Phone"
Form2.txtFieldName.Text = "Phone"
End If
dvDonors.Table = dsDataSet.Donors
dvDonors.RowFilter = myField & " LIKE" & "'" &
txtSearch.Text & "*" & "'"
Form2.grdGrid.DataSource = dvDonors
' Display the form.
Form2.Show()
txtSelectedKey.Text = SharedVariables.SelectedKey
*** txtSelectedKey.Text after the first execution is Null.
All of this works fine up to this point - I can show the
second form with the filtered data.
Here is the malfunctioning code:
Private Sub grdGrid_DoubleClick(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
grdGrid.DoubleClick
SharedVariables.SelectedKey = grdGrid.Item
(grdGrid.CurrentCell)
End Sub
The shared variable is not updated with the datagrid item
the first time through. (it's null) If you execute the
search again (after closing Form2) you get the datagrid
item from the first execution. Execute it again (3rd
time) you get the item from the 2nd execution and so on.
What is causing this behaviour?
I have a project that uses two forms. Form1 uses a SQL
Connection, several DataAdapters for various tables,
DataSet, and a DataView that I filter by user-selected
field names and associated criteria. Form2 has a couple
of read-only text fields to show the user the search
field and criteria they entered plus a DataGrid that is
populated from the DataView. There is a Public Class
defined to hold shared variables.
Code:
Public Class SharedVariables
Public Shared SelectedKey As String ' Make it shared
End Class
Code:
' Define an instance of the search form
Dim Form2 As New frmSearchResults
' Set the txtSearchingFor textbox and field name
to data from the calling form
Form2.txtSearchingFor.Text = txtSearch.Text
..
..
..
If cboSearch.SelectedIndex = 5 Then
myField = "Phone"
Form2.txtFieldName.Text = "Phone"
End If
dvDonors.Table = dsDataSet.Donors
dvDonors.RowFilter = myField & " LIKE" & "'" &
txtSearch.Text & "*" & "'"
Form2.grdGrid.DataSource = dvDonors
' Display the form.
Form2.Show()
txtSelectedKey.Text = SharedVariables.SelectedKey
*** txtSelectedKey.Text after the first execution is Null.
All of this works fine up to this point - I can show the
second form with the filtered data.
Here is the malfunctioning code:
Private Sub grdGrid_DoubleClick(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
grdGrid.DoubleClick
SharedVariables.SelectedKey = grdGrid.Item
(grdGrid.CurrentCell)
End Sub
The shared variable is not updated with the datagrid item
the first time through. (it's null) If you execute the
search again (after closing Form2) you get the datagrid
item from the first execution. Execute it again (3rd
time) you get the item from the 2nd execution and so on.
What is causing this behaviour?