Reputation: 73
I am facing a serious issue with a lookup window, Please help to solve this.
see the steps of my form opens
Opens first form (from Dashboard)
Dim ObjOrder As New OrderFormFrm
ObjOrder.USER = USER
ObjOrder.Show()
Next I have to open a popwindow based on a textbox event.
Private Sub txtCustCode_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtCustCode.MouseClick
Dim PopUpCustomer As New searchCustomerfrm
PopUpCustomer.ShowDialog()
End Sub
I have to goback to Orderform with a value based on a gridview row click event
Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick
OrderFormFrm.txtCustCode.Text = Val(DGVCustomer.Item(1, e.RowIndex).Value)`
Me.Close()
End Sub
The problems is, I am getting value to Orderform's textbox when I start project form from 'OrderFormFrm'
(project properties setting-start form), and not getting if I started project from the dashboard.
I need to display the value 'DGVCustomer.Item(1, e.RowIndex).Value'
in Order forms text box 'txtCustCode'
Please help to solve this
Upvotes: 0
Views: 78
Reputation: 110
you could make a shared function on the searchCustomerfrm
form that returns the value that you expect from the form:
Public Shared Function GetCustomer()
Dim PopUpCustomer As New searchCustomerfrm
If PopUpCustomer.ShowDialog() = DialogResult.OK Then
Return Val(PopUpCustomer.DGVCustomer.Item(1, PopUpCustomer.DGVCustomer.CurrentRow.Index).Value)
Else
Return Nothing
End If
End Function
On the DGVCustomer_CellContentDoubleClick
write this:
Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick
Me.DialogResult = DialogResult.OK
End Sub
To call the searchCustomerfrm
from OrderFormFrm
you'll have this code:
txtCustCode.Text = searchCustomerfrm.GetCustomer
Upvotes: 1
Reputation: 510
Unless I missed something, you need to be calling the original form by instance name and not by type...
Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick
ObjOrder.txtCustCode.Text = Val(DGVCustomer.Item(1, e.RowIndex).Value)
Me.Close()
End Sub
Upvotes: 0
Reputation: 510
add a public property called sendingForm to your searchCustomerFrm class
Public Class searchCustomerFrm
Public sendingForm As OrderFormFrm
Then set that property to the sending form when you create the new form
Private Sub txtCustCode_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtCustCode.MouseClick
Dim PopUpCustomer As New searchCustomerfrm
PopUpCustomer.sendingForm = Me
PopUpCustomer.ShowDialog()
End Sub
Finally, set the textbox property of the sending form
Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick
sendingForm.txtCustCode.Text = Val(dgvCustomer.Item(1, e.RowIndex).Value)
Me.Close()
End Sub
Upvotes: 0