从另一种形式触发事件

时间:2012-02-19 05:05:44

标签: vb.net

大家好我在我的ViewProductsInventory(我的MainForm ShowDialog中调用了此代码):

 Private Sub ViewProductsInventory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Tb_inventory_datesTableAdapter.Fill(Me.InventorySysDataSet.tb_inventory_dates)
    Dim inventory_date As Date
    inventory_date = Me.cboInventoryDate.Text

End Sub


Public Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    Dim inventory_date As String
    inventory_date = Me.cboInventoryDate.Text

    'this part populates my datagridview1
    Me.SP_GetInventoryTableAdapter.Fill(Me.InventorySysDataSet.SP_GetInventory, inventory_date)
End Sub
单击编辑按钮后,

将执行EditForm.ShowDialog()

在我的EditForm中,记录将被更新,之后将触发ViewProductsInventory.btnSearch_Click( ViewProductsInventory.btnSearch, EventArgs.Empty)

然后错误“从字符串转换”“到'类型'日期'无效”发生。

我尝试了Msgbox(Me.cboInventoryDate.Text)并且没有返回任何内容。我假设我的cboInventoryDate目前没有填充,因此当btnSearch_Click被触发时,它什么都没有收到。

我该如何解决这个问题?请帮助我。 TIA!

1 个答案:

答案 0 :(得分:2)

btnSearch_Click事件中尝试这样的事情:

If Me.cboInventoryDate.Items.Count > 0 then
    Me.cboInventoryDate.SelectedIndex = 0
    inventory_date = Me.cboInventoryDate.Text

    'this part populates my datagridview1  
    Me.SP_GetInventoryTableAdapter.Fill(Me.InventorySysDataSet.SP_GetInventory, inventory_date)

End If