|
-
May 10th, 2007, 11:13 AM
#1
Thread Starter
Fanatic Member
[2005] Thread and combobox = X Files Episode??
Ok this is weird.....I setup my form with a combobox and treeview. Initially I setup the combox to be filled on entering the form. Got everything working the way I wanted and then added a backgroundworker to make things integrate better, be better visually, yadda yadda yadda. Once I implemented the backgroundworker my combobox loaded with no problems, however when I tried to use the indexchanged event to load the treeview, it was like the combobox lost one of its items/shifted them up or something. I look at the combobox it has:
Item0 = A
Item1 = B
Item2 = C
Item3 = D
I click on "C". The program is telling me I clicked on "D". Accoring to the immediate window Item0 = B, Item1 = C, Item2 = D and A is not there. I commented out the backgroundworker and it worked fine. I stepped through the code and could not see anything that did not work as it should.....Help?!
Code:
Private Sub tabpage1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabpage1.Enter
combobox1.Items.Clear()
'Timer interval set to 1000 (1 second)
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
If combobox1.Items.Count = 0 Then
Me.Cursor = Cursors.WaitCursor
'backgroundworker1.RunWorkerAsync(GetSqlServers)
Dim bool As Boolean = GetSqlServers()
Me.Cursor = Cursors.Default
End If
End Sub
Private Sub backgroudworker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles backgroudworker1.DoWork
'Reset Progressbar
pgbStatus.Value = 0
pgbStatus.Maximum = 100
e.Result = GetSqlServers()
End Sub
Private Sub backgroundworker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles backgroundworker1.ProgressChanged
pgbStatus.Value = e.ProgressPercentage
End Sub
Private Function GetSqlServers() As Boolean
Dim sdt As New DataTable
Try
'Found Registry Entry for Registered SQL Servers nn Local Machine
'HKEY_CURRENT_USER\Software\Microsoft\MSSQLServer\SQLEW\Registered Servers X\SQL Server Group
Dim Path As String = "Software\\Microsoft\\MSSQLServer\\SQLEW\\Registered Servers X\\SQL Server Group"
Dim servlist As RegistryKey = Registry.CurrentUser.OpenSubKey(Path, True)
'Add Locally registered Servers
For Each valueName As String In servlist.GetValueNames
combobox1.Items.Add(valueName)
Next
'Get SMO Enabled Servers
sdt = SmoApplication.EnumAvailableSqlServers(False)
' Display the list of all available servers
For Each row As DataRow In sdt.Rows
combobox1.Items.Add(row.Item(0).ToString)
Next
'Set first server in list as the default
combobox1.Text = combobox1.Items.Item(0).ToString
Return True
Catch ex As Exception
Return False
Finally
If Not IsNothing(sdt) Then
sdt.Dispose()
sdt = Nothing
End If
End Try
End Function
Private Sub combobox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles combobox1.SelectedIndexChanged
'clear treeview
treeview1.Nodes.Clear()
Me.Cursor = Cursors.AppStarting
'Connect to Selected Server and get a list of available databases
Dim xl As New xmlrgex 'Custom Class
Try
Dim dt As DataTable = xl.ADOSchema(combobox1.SelectedItem) 'Gets the Database list from the Server
'MsgBox(dt.Rows.Count)
If IsNothing(dt) Or dt.Rows.Count = 0 Then
MsgBox("Failed to get Databases")
Exit Sub
End If
Dim ndP As New TreeNode(combobox1.Text)
treeview1.Nodes.Add(ndP)
ndP.Tag = combobox1.Text
Dim ndC As TreeNode
Dim dummynode As TreeNode
For Each row As DataRow In dt.Rows
ndC = New TreeNode(row.Item(0).ToString)
dummynode = New TreeNode
ndP.Nodes.Add(ndC)
ndC.Tag = row.Item(0).ToString
ndC.Nodes.Add(dummynode)
Next
ndP = Nothing
dt.Dispose()
dt = Nothing
Catch ex As Exception
'MsgBox(ex.Message)
Finally
xl = Nothing
Me.Cursor = Cursors.Default
End Try
End Sub
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|