调用委托子VB.Net

时间:2015-09-02 11:56:33

标签: vb.net textbox delegates

我正在为我们的部门开发库存应用程序。我目前正在发布收据。物品可以从供应商处收到或从员工处退回。如果从员工收到材料,那么我会显示另一个显示员工列表的表单,然后用户选择该员工。选择员工后,我会声明一个委托并在原始收据表单中调用一个子,以更新具有员工ID和姓名的TextBox。 问题是TextBox没有使用我通过委托的字符串进行更新。 我调试了应用程序并发现在子接收到的值,但TextBox未更新

这是我的代码 员工选择表中的此代码

Public Class frmReceiptEmployeeSelection
    ...

    Private Sub dgvEmployee_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvEmployee.CellClick
        If e.RowIndex >= 0 And e.ColumnIndex = dgvEmployee.Columns("employeeSelect").Index Then
            Dim employeeId As Integer = dgvEmployee.Rows(e.RowIndex).Cells("employeeId").Value
            Dim selectionText As String = dgvEmployee.Rows(e.RowIndex).Cells("employeeNewCode").Value
            selectionText += "," + dgvEmployee.Rows(e.RowIndex).Cells("employeeName").Value

            Dim employeeSelectionDel As New EmployeeSelectionDelegate(AddressOf frmAddReceipt.selectEmployeeForReceipt)
            employeeSelectionDel.Invoke(employeeId, selectionText)
            Me.Close()
        End If
    End Sub
End Class

以下是收据表格中的代码:

Public Delegate Sub EmployeeSelectionDelegate(ByVal x As Integer, ByVal s As String)

Public Class frmAddReceipt
    ...

    Public Sub selectEmployeeForReceipt(ByVal employeeId As Integer, ByVal selectionText As String)
        selectedEmployeeId = employeeId
        txtReceiptEmployeeSelection.Text = selectionText
    End Sub
End Class

我花了太多时间寻找一个解决方案,用传递的字符串通过委托更新TextBox,但没有成功。

感谢您的帮助。

0 个答案:

没有答案