Solved

How to programatically change ComboBox selection

Posted on 2010-11-26
6
384 Views
Last Modified: 2012-05-10
After a record is saved in my application, a combobox is refilled to include the new item.  How do I programatically move the position of the combobox to the new record?

Thanks!
0
Comment
Question by:Agent909
  • 4
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34220514
Assuming you are adding to the end of the list:
Me.comboBox1.SelectedIndex = Me.comboBox1.Items.Count - 1

Open in new window

0
 
LVL 1

Author Comment

by:Agent909
ID: 34220518
Actually, the list is sorted first, so it won't be the last item.
0
 
LVL 1

Author Comment

by:Agent909
ID: 34220527
The values in the combobox are:

Description - what's shown
RecordID - the index
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:Agent909
ID: 34220586
I discovered that the values in my combobox are objects.  Here's some code I used to test this.  So, there's got to be a way to access the recordID to set the combobox's SelectedValue.  

        Dim obj As WebPage
        For Each obj In cboSites.Items()
            ' this does work
            Debug.Print(obj.SiteDescription)
            ' this will hang
            If obj.SiteDescription = "Google" Then
                cboSites.SelectedValue = obj.RecordID
            End If
        Next

Open in new window

0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 34220651
Try this:
Dim obj As WebPage

        For Each obj In cboSites.Items()

            If obj.SiteDescription = "Google" Then

                cboSites.SelectedItem = obj

                Exit For

            End If

        Next

Open in new window

0
 
LVL 1

Author Closing Comment

by:Agent909
ID: 34220698
Your code is sending me in the right direction.  Thank you!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now