Solved

How to programatically change ComboBox selection

Posted on 2010-11-26
6
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

738 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