Solved

How to programatically change ComboBox selection

Posted on 2010-11-26
6
386 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 75

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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