大家好,我的 ViewProductsInventory
中有这段代码(由 ShowDialog
从我的 MainForm
调用):
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!
最佳答案
在您的 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
关于vb.net - 从另一个表单触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346898/