强制呼叫选择改变了事件 [英] force call selection changed event
问题描述
我有一个正在研究的VB项目,我不能,在我的生活中,记住如何强制调用SelectionChanged事件。以下是我要调用的代码...
I have a VB project I am working on and I can't, for the life of me, remember how to force call a SelectionChanged event. Below is the code I am trying to call...
Private Sub cbxName_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles cbxName.SelectionChanged
Try
Dim cmb As ComboBox = sender
Dim i As Integer = cmb.SelectedIndex
Dim cust As Customer = Customers(i)
Me.DataContext = cust
Catch ex As Exception
End Try
End Sub
...这里是我试图调用它的代码。 (我这样做,因为出于某种原因,当我的If / Then语句触发时,不会调用sub。)
...and here is the code where I am trying to call it. (I'm doing it this way, because for some reason the sub isn't being called when my If/Then statement fires.)
Private Sub RetrieveProperties()
Try
If appDRAW.Documents.Count = 0 Then Exit Sub
dcmnt = appDRAW.ActiveDocument
If dcmnt.FileName <> "" Then txbPONum.Text = Left(dcmnt.FileName, Len(dcmnt.FileName) - 4) Else txbPONum.Text = ""
If dcmnt.Properties.Exists("Customer", 1) Then cbxName.Text = dcmnt.Properties("Customer", 1)
'FORCE CALL cbxName_SelectionChanged
...
Catch ex As Exception
MessageBox.Show("Can't Retrieve Properties:" & vbLf & ex.Message)
End Try
End Sub
我想的可能是...... 。
如果Customers.Contains(dcmnt.Properties(Customer,1))则cbxName.Text = [查询的索引是什么。]
如何确定查询选择索引是什么?或者我如何完成if语句?
I'm thinking maybe something like...
If Customers.Contains(dcmnt.Properties("Customer", 1)) then cbxName.Text = [what ever the index of the query was.]
How do I figure out what the query selection index is? or how would I complete that if statement?
推荐答案
为什么强制呼叫什么?为什么不直接将事件处理程序中的代码移动到一个单独的方法中并从两个地方调用它?
Why "force call" anything? Why not just move the code from your event handler into a separate method and call that from two places?
这篇关于强制呼叫选择改变了事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!