-1

我正在尝试将 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 中显示 ok。

在 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
4

1 回答 1

1

instead of putting the code within the txtDeptCustomer.TextChanged sub, try putting it within the frmDepartment_load:

Private Sub frmDepartment_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load            
    txtDeptCustomer.Text = frmMain.txtCustomerActive.Text
End Sub

or you could set the frmDepartment text box text on the frmMain button click:

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
于 2013-10-15T16:13:54.320 回答