Solved

How to programatically change ComboBox selection

Posted on 2010-11-26
6
387 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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