|
-
Oct 9th, 2013, 09:46 AM
#1
Thread Starter
Member
[RESOLVED] Pre-selecting item in ComboBox - "Operation is not allowed when the object is open"
Hello.
In the form load event, I am populating a combobox with items from a database query. I then want to pre-select one of the items. This worked fine under VB6 but I am currently upgrading the code to .Net, and I am getting the error "Operation is not allowed when the object is open". I cannot seem to get by this. Below is my code.
NOTE: I tried using both methods: setting the Text property, as well as the SelectedIndex property (commented), and get the same error.
Code:
i = 0
Do While Not rs.EOF
i = i + 1
cboUsers.Items.Add((rs.Fields(0).Value))
If rs.Fields(0).Value = LANID Then
cboUsers.Text = rs.Fields(0).Value
'cboUsers.SelectedIndex = i
End If
rs.MoveNext()
Loop
Thanks in advance,
Paul
-
Oct 9th, 2013, 10:20 AM
#2
Thread Starter
Member
Re: Pre-selecting item in ComboBox - "Operation is not allowed when the object is ope
Never mind 
I just figured out that when I set the item, the 'selectedIndexChanged' event fires. In that event, the code is making a db connection, and it is THAT connection that is causing the error because the connection is already open.
Figures I waste hours on this, and 5 minutes after I submit a post, I figure it out!
Thanks anyway,
Paul
Tags for this Thread
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
|