我正在尝试将frmMain上的文本框值传递给frmDepartment上的文本框。我已经尝试了以下代码,我认为它可以工作,但它不会。我是VB的新用户,来自php背景,设置一个简单的任务是一个简单的任务。有人能帮忙吗?如果您需要查看更多代码,请询问。非常感谢
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
在frmMain,我得到这样的价值:
Dim value As Object = UserDataGridView.Rows(e.RowIndex).Cells(0).Value
txtCustomerActive.Text = CType(value, String)
Private Sub btnDepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepts.Click
frmDepartment.Show()
End Sub
在frmMain中显示哪个。
在frmDepartment我有这个代码
Private Sub txtDeptCustomer_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDeptCustomer.TextChanged
'Dim customer As String
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub
答案 0 :(得分:1)
而不是将代码放在txtDeptCustomer.TextChanged子中,尝试将其放在frmDepartment_load中:
Private Sub frmDepartment_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub
或者您可以在frmMain按钮上单击设置frmDepartment文本框文本:
Private Sub btnDepts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepts.Click
frmDepartment.txtDeptCustomer.Text = txtCustomerActive.Text
frmDepartment.Show()
End Sub