我有一個內置.NET 2.0選項卡控件的單個實例的模態窗體。該選項卡控件有幾個頁面,其中之一是一個組合框,在用戶第一次激活它之前不會填充該組合框。當發生這種情況時,我會處理DropDown事件並運行需要幾秒鐘的進程,然後將該進程返回的項目添加到組合框中。在選項卡控件上組合框下拉菜單意外關閉
它工作正常,除了組合框的列表部分被放下之後,它立即關閉,就好像其他控件佔用焦點一樣。我將它縮小到表單上有一個選項卡控件,並且檢索組合框項目的過程需要超過4秒。如果我只用組合框創建一個完全空白的表單,我不會看到這種行爲。
不用說,這是奇怪的超出信念。任何想法爲什麼選項卡控件會干擾當前具有焦點的控件?
編輯:
這是給定的組合框的事件處理程序代碼。基本上我正在建立一個網絡上的SQL服務器列表。需要幾秒鐘的事情是對GetDataSources的調用。
Private Sub cmbServer_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbServer.DropDown
Dim oTable As DataTable
Dim lstServers As List(Of String)
Dim lstAliases As List(Of String)
Try
If cmbServer.Items.Count = 0 Then
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
oTable = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources
lstServers = New List(Of String)
For Each oRow As DataRow In oTable.Rows
If oRow("InstanceName").ToString = "" Then
lstServers.Add(oRow("ServerName").ToString)
Else
lstServers.Add(oRow("ServerName").ToString & "\" & oRow("InstanceName").ToString)
End If
Next oRow
'Retrieve any server aliases on the client and add them to the server list
lstAliases = GetSQLServerAliases()
If lstAliases IsNot Nothing Then
For Each sAlias As String In lstAliases
lstServers.Add(sAlias)
Next sAlias
End If
lstServers.Sort()
For Each sServer As String In lstServers
cmbServer.Items.Add(sServer)
Next sServer
End If
Catch ex As Exception
ErrHandler("frmRefreshDB", "cmbServer_DropDown", ex.Source, ex.Message, ex.InnerException)
Finally
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
If oTable IsNot Nothing Then
oTable.Dispose()
End If
End Try
End Sub
該選項卡控件臭名昭着造成焦點問題和其他問題與子控件。我從來沒有見過這個問題,但我會嘗試複製它。 – 2009-05-22 19:28:36